mibes / couch-rs

CouchDB library for Rust
Apache License 2.0
59 stars 17 forks source link

Consider way to differentiate errors #21

Closed jgrund closed 2 years ago

jgrund commented 2 years ago

It's not easy to tell if a CouchError originated from something like a failure to Deserialize or some other cause. This is because CouchError is a struct rather than an enum and multiple items all get the same status:

https://github.com/mibes/couch-rs/blob/f15ba8b79c8d9a3fb218e3f20a4762ea55967db6/couch_rs/src/error.rs#L74-L102

Consider making CouchError an enum so downstream consumers can match over the Error types and not have to resort to string matching on message.

mibes commented 2 years ago

@jgrund, thanks for the suggestion. I believe this would be a good enhancement.

A first version of this implementation can be found in the develop branch. Maybe you can have a quick look and see if this suits your use case.

jgrund commented 2 years ago

Hi,

Thanks for addressing this.

I tried out the latest develop branch, but got a compilation error trying to use Database within a tokio::spawn.

This is because UpstreamError is wrapped in Rc, which is not Send, and also because inner type is not Send + Sync.

I'll open a PR to fix

jgrund commented 2 years ago

https://github.com/mibes/couch-rs/pull/22

mibes commented 2 years ago

Changes have been released as part of couch_rs v0.9.0