[pbs-devel] [PATCH proxmox] fixup! CLI: print fatal errors including causes

Max Carrara m.carrara at proxmox.com
Wed Feb 21 17:52:10 CET 2024


---
 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





More information about the pbs-devel mailing list