@@ -246,25 +246,25 @@ The usage of `thiserror` is considered invalid.
246
246
----
247
247
#[derive(thiserror::Error)]
248
248
enum Error {
249
- #[error("failed to read config file")]
250
- FileRead(#[from] std::io::Error)
249
+ #[error("failed to read config file")]
250
+ FileRead(#[from] std::io::Error)
251
251
}
252
252
253
253
fn config_file(user: User) -> Result<(), Error> {
254
- std::fs::read_to_string(user.file_path)?;
254
+ std::fs::read_to_string(user.file_path)?;
255
255
}
256
256
----
257
257
258
258
[source,rust]
259
259
----
260
260
#[derive(Snafu)]
261
261
enum Error {
262
- #[snafu(context(false))]
263
- FileRead { source: std::io::Error }
262
+ #[snafu(context(false))]
263
+ FileRead { source: std::io::Error }
264
264
}
265
265
266
266
fn config_file(user: User) -> Result<(), Error> {
267
- std::fs::read_to_string(user.file_path)?;
267
+ std::fs::read_to_string(user.file_path)?;
268
268
}
269
269
----
270
270
@@ -277,17 +277,54 @@ fn config_file(user: User) -> Result<(), Error> {
277
277
----
278
278
#[derive(Snafu)]
279
279
enum Error {
280
- #[snafu(display("failed to read config file of user {user_name}"))]
281
- FileRead {
282
- source: std::io::Error,
283
- user_name: String,
284
- }
280
+ #[snafu(display("failed to read config file of user {user_name}"))]
281
+ FileRead {
282
+ source: std::io::Error,
283
+ user_name: String,
284
+ }
285
285
}
286
286
287
287
fn config_file(user: User) -> Result<(), Error> {
288
- std::fs::read_to_string(user.file_path).context(FileReadSnafu {
289
- user_name: user.name,
290
- });
288
+ std::fs::read_to_string(user.file_path).context(FileReadSnafu {
289
+ user_name: user.name,
290
+ });
291
+ }
292
+ ----
293
+
294
+ ====
295
+
296
+ === Error variant names
297
+
298
+ All error variants must not include any unnesecarry prefixes or suffixes.
299
+ Examples of such prefixes include (but are not limited to) `FailedTo` and `UnableTo`.
300
+ Furthermore, examples for suffixes are `Error` or `Snafu`
301
+ Error variant names must however include verbs or identifiers as a prefix.
302
+
303
+ [WARNING.code-rule,caption=Examples of incorrect code for this rule]
304
+ ====
305
+
306
+ [source,rust]
307
+ ----
308
+ #[derive(Snafu)]
309
+ enum Error {
310
+ FailedToParseConfig,
311
+ HttpRequestError,
312
+ ConfigRead,
313
+ }
314
+ ----
315
+
316
+ ====
317
+
318
+ [TIP.code-rule,caption=Examples of correct code for this rule]
319
+ ====
320
+
321
+ [source,rust]
322
+ ----
323
+ #[derive(Snafu)]
324
+ enum Error {
325
+ ParseConfig,
326
+ HttpRequest,
327
+ ReadConfig,
291
328
}
292
329
----
293
330
@@ -305,14 +342,14 @@ It is recommended to start the error messages with "failed to..." or "unable to
305
342
----
306
343
#[derive(Snafu)]
307
344
enum Error {
308
- #[snafu(display("Foo happened."))]
309
- Foo,
345
+ #[snafu(display("Foo happened."))]
346
+ Foo,
310
347
311
- #[snafu(display("Bar encountered"))]
312
- Bar,
348
+ #[snafu(display("Bar encountered"))]
349
+ Bar,
313
350
314
- #[snafu(display("arghh baz."))]
315
- Baz,
351
+ #[snafu(display("arghh baz."))]
352
+ Baz,
316
353
}
317
354
----
318
355
@@ -325,11 +362,11 @@ enum Error {
325
362
----
326
363
#[derive(Snafu)]
327
364
enum Error {
328
- #[snafu(display("failed to foo"))]
329
- Foo,
365
+ #[snafu(display("failed to foo"))]
366
+ Foo,
330
367
331
- #[snafu(display("unable to bar"))]
332
- Bar,
368
+ #[snafu(display("unable to bar"))]
369
+ Bar,
333
370
}
334
371
----
335
372
0 commit comments