You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs(code-style-guide): Add section about unwraps (#741)
* docs(code-style-guide): Add section about unwraps
* chore: Apply suggestions
Co-authored-by: Nick <10092581+NickLarsenNZ@users.noreply.github.com>
* chore(code-style-guide): Use link definitions
* chore(code-style-guide): Add bad unwrap example for tests
* chore: Apply suggestions from code review
Co-authored-by: Nick <10092581+NickLarsenNZ@users.noreply.github.com>
* chore: Apply suggestion
Co-authored-by: Nick <10092581+NickLarsenNZ@users.noreply.github.com>
---------
Co-authored-by: Nick <10092581+NickLarsenNZ@users.noreply.github.com>
The `unwrap` function must not be used in any code.
541
+
Instead, proper error handling like above should be used, unless there is a valid reason to use `expect` described below.
542
+
Using link:{unwrap_or}[`unwrap_or`], link:{unwrap_or_default}[`unwrap_or_default`] or link:{unwrap_or_else}[`unwrap_or_else`] is allowed because these functions will not panic.
543
+
544
+
The `expect` function can be used when external factors cannot influence whether a panic will happen. For example, when compiling regular expressions inside const/static environments.
545
+
For such cases code must use `expect` instead of `unwrap` to provide additional context for why a particular piece of code should never fail.
546
+
547
+
// Do we want to mention that this is enforced via clippy and that we actually enable that lint in our repos?
548
+
549
+
[TIP.code-rule,caption=Examples of correct code for this rule]
0 commit comments