diff options
author | har7an <99636919+har7an@users.noreply.github.com> | 2022-10-18 14:14:38 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-18 14:14:38 +0000 |
commit | 0711591ad3995d0201f830acb06127952c8d4391 (patch) | |
tree | 1da9aa0220041417aafbf0da1eb8ef2730fccf37 /CONTRIBUTING.md | |
parent | 12d35bded55756c951e86212a3c72305a26043d6 (diff) |
docs: Describe how to handle Options as errors (#1805)
* docs: Describe how to handle Options as errors
* CONTRIBUTING: Add tips for code contributions
which will be home to condensed tips and best-practices around the
zellij code. Currently explains to prefer returning `Result` types
instead of `unwrap`ing on them.
The tips in here are meant to be short, concise guides that allow the
user to get started without a lot of reading. The individual tips can
(and should) be supplemented with links to "further reading" where the
topic at hand is explained in greater detail.
Diffstat (limited to 'CONTRIBUTING.md')
-rw-r--r-- | CONTRIBUTING.md | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0f62b09ef..59159a982 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -113,6 +113,21 @@ something interesting to work on and guide through. [discord-invite-link]: https://discord.gg/feHDHahHCz [good-first-issue]: https://github.com/zellij-org/zellij/labels/good%20first%20issue + +## Tips for Code Contributions + +### Prefer returning `Result`s instead of `unwrap`ing + +- Add `use zellij_utils::errors::prelude::*;` to the file +- Make the function return `Result<T>`, with an appropriate `T` (Use `()` if there's nothing to return) +- Append `.context()` to any `Result` you get with a sensible error description (see [the docs][error-docs-context]) +- Generate ad-hoc errors with `anyhow!(<SOME MESSAGE>)` +- *Further reading*: [See here][error-docs-result] + +[error-docs-context]: https://github.com/zellij-org/zellij/blob/main/docs/ERROR_HANDLING.md#attaching-context +[error-docs-result]: https://github.com/zellij-org/zellij/blob/main/docs/ERROR_HANDLING.md#converting-a-function-to-return-a-result-type + + ## Filing Issues Bugs and enhancement suggestions are tracked as GitHub issues. |