Skip to content

Commit 2022a1b

Browse files
committed
Explain some points why we use snafu
1 parent f256324 commit 2022a1b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

modules/contributor/pages/code-style-guide.adoc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,16 @@ enum Error {
203203

204204
=== Choice of error crate and usage
205205

206-
We use `snafu` for all error handling in library *and* application code.
206+
We use `snafu` for all error handling in library *and* application code because we want to provide as much context to the user as possible.
207+
Further, `snafu` allows us to use the same source error in multiple error variants.
208+
This feature can be used for cases were we need / require more fine-grained error variants.
209+
This behaviour is not possible when using `thiserror`, as it uses the `From` trait to convert the source error into an error variant.
210+
207211
Additionally, we restrict the usage of the `#[snafu(context(false))]` atrribute on error variants.
208212
This ensures that fallible functions need to call `.context()` to pass the error along.
209213

214+
The usage of `thiserror` is considered invalid.
215+
210216
[WARNING.code-rule,caption=Examples of incorrect code for this rule]
211217
====
212218

0 commit comments

Comments
 (0)