monero-rpc-rs icon indicating copy to clipboard operation
monero-rpc-rs copied to clipboard

Error handling without anyhow

Open xorpd opened this issue 3 years ago • 3 comments

Hi, thank you for writing this library!

I noticed that most of the exported API functions in this library return anyhow results. Being new to the rust error handling ecosystem, I was wondering if as an application developer I will also have to use anyhow to handle errors, or will I still be able to use the traditional Result<>, like I have always done.

I have been searching for a Rust library that could help me with XMR payment processing, and this library seems like on of the only options, so I will probably use it anyways (: But I am asking ahead of time just to know if I will have to make some compromises with the rest of my application code.

Thanks!

xorpd avatar Nov 29 '21 19:11 xorpd

Hey, I came back after learning a bit about anyhow. I read this sentence on anyhow's project readme:

Use Anyhow if you don't care what error type your functions return, you just want it to be easy. This is common in application code. Use thiserror if you are a library that wants to design your own dedicated error type(s) so that on failures the caller gets exactly the information that you choose. (https://github.com/dtolnay/anyhow#comparison-to-thiserror)

If we want monero-rpc-rs to be a library used by rust applications, maybe it could be a good idea to use something like thiserror?

xorpd avatar Dec 02 '21 08:12 xorpd

Interoperability wise it is better for a library to use thiserror IMO, as it doesn't impose a dependency on downstream projects. But I don't know the rational of @vorot93 when this was first created, nor if/when we would consider a switch from anyhow to thiserror.

h4sh3d avatar Dec 02 '21 10:12 h4sh3d

Possible errors for the RPC are in:

  • https://github.com/monero-project/monero/blob/master/src/rpc/core_rpc_server_error_codes.h
  • https://github.com/monero-project/monero/blob/master/src/wallet/wallet_rpc_server_error_codes.h

LeoNero avatar Jul 17 '22 22:07 LeoNero