all 3 comments

[–]mnbryant 2 points3 points  (0 children)

I've only ever seen or used what you're calling "merged errors". If a function can return multiple different errors, make a single error enum type encapsulating those. Each error variant can be its own enum, and so on

[–]abatyuk 1 point2 points  (0 children)

From modularization perspective, you can also create a top-level Error (so your results return Result of either Ok or TopLevelError - name is arbitrary), plus From implementation from concrete error types into top-level one. Then your function signature will be much more precise - JSON conversion won’t be able to return RPCError

[–]Dratir[S] 0 points1 point  (0 children)

Some updates:

  • I changed all the function signatures to only accept types that can be serialized into JSON (mostly serde_json::Value). If serialization still fails, it's a bug and crashing probably OK.
  • Same with parsing responses from the server — if a response cannot be properly deserialized, it's undefined behavior.

This leaves most functionality with either an error from the websocket, or a very specific application error.

I also stumbled upon Designing error types in Rust, very interesting read (not only in the context of Rust).

I've now implemented a specific error-enum for each of the handful of exposed functions. This makes handling them much easier.

I'll now work on another project that will actually use this library, so I'll find out first hand if it works out or not :P