Skip to content

Commit fae529a

Browse files
committed
Add a few rules of thumb for error messages
1 parent ae09e54 commit fae529a

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,7 @@ fn config_file(user: User) -> Result<(), Error> {
296296
=== Error messages
297297

298298
All our error messages must start with a lowercase letter and must not end with a dot.
299-
Additionally, critical (unrecoverable) errors should start with "failed to ...".
300-
Potentially recoverable errors should start with "unable to ...".
299+
It is recommended to start the error messages with "failed to..." or "unable to ...".
301300

302301
[WARNING.code-rule,caption=Examples of incorrect code for this rule]
303302
====
@@ -336,6 +335,16 @@ enum Error {
336335
337336
====
338337

338+
==== Examples for "failed to ..." error messages
339+
340+
. `failed to parse config file` to indicate the parsing of the config file failed, usually because the file doesn't conform to the configuration language.
341+
. `failed to construct http client` to indicate we wanted to construct a HTTP client to retrieve remote content.
342+
343+
==== Exampled for "unable to ..." error messages
344+
345+
. `unable to read config file from ...` to indicate we could load the file (for example because the file doesn't exist).
346+
. `unable to parse value ...` to indicate we failed to parse a user provided value which didn't conform to the expected syntax.
347+
339348
== String formatting
340349

341350
=== Named versus unnamed format string identifiers

0 commit comments

Comments
 (0)