From d2b15cb6290a9909676781c3c4a1bfb96a995fe8 Mon Sep 17 00:00:00 2001 From: link2xt Date: Sat, 8 Jul 2023 19:49:12 +0000 Subject: [PATCH] docs: document how logs and error messages should be formatted --- CONTRIBUTING.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5bb9ea6f6..0285b2697 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -76,6 +76,29 @@ If you have multiple changes in one PR, create multiple conventional commits, an [Conventional Commits]: https://www.conventionalcommits.org/ [git-cliff]: https://git-cliff.org/ +### Errors + +Delta Chat core mostly uses [`anyhow`](https://docs.rs/anyhow/) errors. +When using [`Context`](https://docs.rs/anyhow/latest/anyhow/trait.Context.html), +capitalize it but do not add a full stop as the contexts will be separated by `:`. +For example: +``` +.with_context(|| format!("Unable to trash message {msg_id}")) +``` + +### Logging + +For logging, use `info!`, `warn!` and `error!` macros. +Log messages should be capitalized and have a full stop in the end. For example: +``` +info!(context, "Ignoring addition of {added_addr:?} to {chat_id}."); +``` + +Format anyhow errors with `{:#}` to print all the contexts like this: +``` +error!(context, "Failed to set selfavatar timestamp: {err:#}."); +``` + ### Reviewing Once a PR has an approval and passes CI, it can be merged.