From: Max Carrara <m.carrara@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox] fixup! CLI: print fatal errors including causes
Date: Wed, 21 Feb 2024 17:52:10 +0100 [thread overview]
Message-ID: <20240221165210.428072-1-m.carrara@proxmox.com> (raw)
In-Reply-To: <20240220102859.71349-2-g.goller@proxmox.com>
---
proxmox-router/README.rst | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/proxmox-router/README.rst b/proxmox-router/README.rst
index 9c7c2139..5fef633f 100644
--- a/proxmox-router/README.rst
+++ b/proxmox-router/README.rst
@@ -1,13 +1,13 @@
-================
- proxmox-router
-================
+proxmox-router
+==============
-cli
-==================
-To improve our error handling story, we use anyhow and `.context()` on
-all errors. This means no more `format_err()` and `format()` of errors.
+Command Line
+------------
-For example, with two calls to `.with_context` when bubbling up errors in
+To improve our error handling story, we use anyhow and ``.context()`` on
+all errors. This means no more ``format_err()`` and ``format()`` of errors.
+
+For example, with two calls to ``.with_context`` when bubbling up errors in
proxmox-offline-mirror:
.. code-block::
@@ -18,11 +18,11 @@ proxmox-offline-mirror:
@@ -1,7 +1,7 @@
use std::fmt::Display;
use std::path::Path;
-
+
-use anyhow::{bail, Error};
+use anyhow::{bail, format_err, Context, Error};
use serde_json::Value;
-
+
use proxmox_router::cli::{run_cli_command, CliCommand, CliCommandMap, CliEnvironment};
@@ -676,7 +676,8 @@ async fn setup(config: Option<String>, _param: Value) -> Result<(), Error> {
Action::AddMirror => {
@@ -41,7 +41,7 @@ proxmox-offline-mirror:
@@ -7,7 +7,7 @@ use std::{
path::{Path, PathBuf},
};
-
+
-use anyhow::{bail, format_err, Error};
+use anyhow::{bail, format_err, Context, Error};
use nix::{unistd, NixPath};
@@ -49,7 +49,7 @@ proxmox-offline-mirror:
use proxmox_apt::deb822::CheckSums;
@@ -45,10 +45,12 @@ impl Pool {
}
-
+
if !pool.exists() {
- create_path(pool, None, None)?;
+ create_path(pool, None, None)
@@ -59,7 +59,7 @@ proxmox-offline-mirror:
- create_path(link_dir, None, None)?;
+ create_path(link_dir, None, None)
+ .with_context(|| format!("Failed to create link dir {link_dir:?}"))?;
-
+
Ok(Self {
pool_dir: pool.to_path_buf(),
@@ -77,14 +77,14 @@ Instead of the original::
Which is not really helpful without knowing the path.
-For non-fatal cases or logging inside tasks, `{:#}` could be used which just
+For non-fatal cases or logging inside tasks, ``{:#}`` could be used which just
prints the causes/contexts in a single line like this::
Failed to initialize mirror 'debian_bullseye_main': Failed to create pool dir "/var/lib/proxmox-offline-mirror/mirrors//.pool": EACCES: Permission denied
but for that usage, the context should be kept short to avoid the line getting overly long.
-One downside to adding context is that the default `Display` implementation will
+One downside to adding context is that the default ``Display`` implementation will
*just* print the context, which hides the root cause::
Error: Failed to initialize mirror 'debian_bullseye_main'
--
2.39.2
next prev parent reply other threads:[~2024-02-21 16:52 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-20 10:28 [pbs-devel] [PATCH v2 proxmox{, -backup} 0/4] output full anyhow context in client Gabriel Goller
2024-02-20 10:28 ` [pbs-devel] [PATCH v2 proxmox 1/4] CLI: print fatal errors including causes Gabriel Goller
2024-02-21 16:45 ` Max Carrara
2024-02-21 16:52 ` Max Carrara [this message]
2024-02-20 10:28 ` [pbs-devel] [PATCH v2 proxmox-backup 2/4] pxar: remove ArchiveError Gabriel Goller
2024-02-20 10:28 ` [pbs-devel] [PATCH v2 proxmox-backup 3/4] pxar: add UniqueContext helper Gabriel Goller
2024-02-20 10:28 ` [pbs-devel] [PATCH v2 proxmox-backup 4/4] pxar: use anyhow::Error in PxarBackupStream Gabriel Goller
2024-04-26 12:00 ` [pbs-devel] [PATCH v2 proxmox{, -backup} 0/4] output full anyhow context in client Gabriel Goller
2024-06-17 8:12 ` Gabriel Goller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240221165210.428072-1-m.carrara@proxmox.com \
--to=m.carrara@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.