ankicommunity/anki-sync-server-rs

Decide on error handling practices

Closed this issue · 1 comments

The current number of unwrap in the code is huge (cf. code block at the end), it makes the server prone to failures, we must fix that.
To lower this number there is a need to handle error properly (layered error handling).

The current best practices in rust are thiserror and anyhow.
Fatal AND non fatal errors should be logged (using error/warn/log/trace mechanism of the log crate), we may benefit migrating to a more complete logging backend (such as fern) down the line. For now I think env_logger should be enough.

I am a proponent of using thiserror as it integrates more tightly and allow control on the error type (which make code safety & maintenance much easier). In comparison anyhow make error return an opaque type making it easier to use but more error prone.
You have my take 😉

@dobefore What are your views on the error library to use ?


Unwrap count:

(src/) $ grep -R -c "unwrap()" 
get_card.sql:0
get_note.sql:0
get_review.sql:0
user.rs:37
main.rs:12
db.rs:1
sync.rs:82
envconfig.rs:14
schema.sql:0
media.rs:27
session.rs:28

Decided by pull request #9, we are using this error.