public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH pve-esxi-import-tools 1/1] improve error handling before mounting
Date: Wed,  8 May 2024 14:41:11 +0200	[thread overview]
Message-ID: <20240508124112.2519552-2-d.csapak@proxmox.com> (raw)
In-Reply-To: <20240508124112.2519552-1-d.csapak@proxmox.com>

when we fail early in the mount process, we did not log any error to the
syslog, but only the top most one to stderr.

sadly we were not able to see them anywhere, so improve the log by
* log the complete error chain with log::error (so we also can see the
  causes)
* add more context hints in main_do

This can help debug issues where we failed early and could not see any
error output otherwise, e.g. this thread in the forum:

https://forum.proxmox.com/threads/146248/

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 src/main.rs | 36 +++++++++++++++++++++++++++---------
 1 file changed, 27 insertions(+), 9 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index 281ec3d..a8b2bb6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,4 +1,5 @@
 use std::ffi::{CString, OsStr, OsString};
+use std::fmt::Write;
 use std::io;
 use std::os::fd::RawFd;
 use std::os::unix::ffi::OsStrExt;
@@ -221,7 +222,12 @@ fn main() {
     });
 
     if let Err(err) = runtime.block_on(main_do()) {
-        eprintln!("Error: {}", err);
+        let mut err_chain = String::new();
+        for err in err.chain() {
+            let _ = writeln!(err_chain, " {err}");
+        }
+        println!("Error: {err}");
+        log::error!("Error: {err_chain}");
         std::process::exit(-1);
     }
 }
@@ -236,15 +242,15 @@ async fn main_do() -> Result<(), Error> {
             usage(&arg0, std::io::stderr(), 1);
         }
     };
-    parse_manifest(&args.manifest)?;
+    parse_manifest(&args.manifest).context("failed to parse manifest")?;
 
     let change_uid = match args.change_user.as_deref() {
-        Some(user) => Some(get_uid(user)?),
+        Some(user) => Some(get_uid(user).context("failed to get uid")?),
         None => None,
     };
 
     let change_gid = match args.change_group.as_deref() {
-        Some(group) => Some(get_gid(group)?),
+        Some(group) => Some(get_gid(group).context("failed to get gid")?),
         None => None,
     };
 
@@ -255,10 +261,12 @@ async fn main_do() -> Result<(), Error> {
         .enable_readdirplus();
 
     for opt in args.mount_options {
-        fuse = fuse.options_os(&opt)?;
+        fuse = fuse
+            .options_os(&opt)
+            .context("failed to get fuse options")?;
     }
 
-    unmount_if_mounted(&args.mount_path)?;
+    unmount_if_mounted(&args.mount_path).context("failed to unmount")?;
 
     let mut fuse = fuse
         .build()
@@ -302,9 +310,19 @@ async fn main_do() -> Result<(), Error> {
             let fs_datastore = fs_datacenter.create_datastore(datastore);
 
             log::debug!("loading {datacenter:?}/{datastore:?}/{path:?}");
-            let config =
-                vmx::VmConfig::parse(client.open_file(datacenter, datastore, path).await?, path)
-                    .await?;
+            let config = vmx::VmConfig::parse(
+                client
+                    .open_file(datacenter, datastore, path)
+                    .await
+                    .with_context(|| {
+                        format!("error opening file for: {datacenter} {datastore} {path}")
+                    })?,
+                path,
+            )
+            .await
+            .with_context(|| {
+                format!("failed to parse vm config for {datacenter} {datastore} {path}")
+            })?;
             log::debug!("{config:#?}");
             for disk in config.disks.values() {
                 let other_fs_datastore;
-- 
2.39.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


  reply	other threads:[~2024-05-08 12:41 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-08 12:41 [pve-devel] [PATCH pve-esxi-import-tools/storage] improve error handling/logging Dominik Csapak
2024-05-08 12:41 ` Dominik Csapak [this message]
2024-05-08 14:26   ` [pve-devel] [PATCH pve-esxi-import-tools 1/1] improve error handling before mounting Thomas Lamprecht
2024-05-10 13:21     ` Dominik Csapak
2024-05-08 12:41 ` [pve-devel] [PATCH storage 1/1] esxi: improve error handling for fuse mount tool Dominik Csapak
2024-05-08 14:43   ` Thomas Lamprecht
2024-05-10 13:28     ` Dominik Csapak

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=20240508124112.2519552-2-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pve-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal