summaryrefslogtreecommitdiffstats
path: root/CONTRIBUTING.md
diff options
context:
space:
mode:
authorhar7an <99636919+har7an@users.noreply.github.com>2022-11-09 18:01:36 +0000
committerGitHub <noreply@github.com>2022-11-09 18:01:36 +0000
commit49b831c032aa4d7f770847ba0c03050a09c80fe1 (patch)
tree9aa6efdc4bd85a47eb08914cd45afc82ad325a24 /CONTRIBUTING.md
parentd4beabfeb294f7abad06891b2f6c9cf07cce60c6 (diff)
docs: Improve error handling docs (#1919)
* docs: Improve error handling docs and add more TL;DRs and new sections about handling specific errors, and logging errors. * contributing: Add more coding tips
Diffstat (limited to 'CONTRIBUTING.md')
-rw-r--r--CONTRIBUTING.md15
1 files changed, 15 insertions, 0 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 59159a982..87eca0941 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -124,8 +124,23 @@ something interesting to work on and guide through.
- Generate ad-hoc errors with `anyhow!(<SOME MESSAGE>)`
- *Further reading*: [See here][error-docs-result]
+### Logging errors
+
+- When there's a `Result` type around, use `.non_fatal()` on that instead of `log::error!`
+- When there's a `Err` type around, use `Err::<(), _>(err).non_fatal()`
+- Also attach context before logging!
+- *Further reading*: [See here][error-docs-logging]
+
+### Adding Concrete Errors, Handling Specific Errors
+
+- Add a new variant to `zellij_utils::errors::ZellijError`, if needed
+- Use `anyhow::Error::downcast_ref::<ZellijError>()` to recover underlying errors
+- *Further reading*: [See here][error-docs-zellijerror]
+
[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
+[error-docs-logging]: https://github.com/zellij-org/zellij/blob/main/docs/ERROR_HANDLING.md#logging-errors
+[error-docs-zellijerror]: https://github.com/zellij-org/zellij/blob/main/docs/ERROR_HANDLING.md#adding-concrete-errors-handling-specific-errors
## Filing Issues