From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 099041FF390 for ; Fri, 10 May 2024 15:57:02 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 960C61EAF8; Fri, 10 May 2024 15:57:02 +0200 (CEST) From: Dominik Csapak To: pve-devel@lists.proxmox.com Date: Fri, 10 May 2024 15:56:57 +0200 Message-Id: <20240510135658.3519714-2-d.csapak@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240510135658.3519714-1-d.csapak@proxmox.com> References: <20240510135658.3519714-1-d.csapak@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.016 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [esxi.rs, proxmox.com, main.rs] Subject: [pve-devel] [PATCH pve-esxi-import-tools v2 1/1] improve error handling before mounting X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" 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 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 --- src/esxi.rs | 7 ++++++- src/main.rs | 15 +++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/esxi.rs b/src/esxi.rs index 6be9466..88930b0 100644 --- a/src/esxi.rs +++ b/src/esxi.rs @@ -278,7 +278,12 @@ impl EsxiClient { ) -> Result { log::debug!("open file [{datacenter}, {datastore}] {path:?}"); let query = self.file_url(datacenter, datastore, path); - let size = self.get_file_size(datacenter, datastore, path).await?; + let size = self + .get_file_size(datacenter, datastore, path) + .await + .with_context(|| { + format!("error when getting file size: {datacenter:?}/{datastore:?}/{path:?}") + })?; Ok(EsxiFile { client: Arc::clone(self), query: query.into(), diff --git a/src/main.rs b/src/main.rs index 281ec3d..216173d 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}"); + } + eprintln!("Error: {err}"); + log::error!("Error:{err_chain}"); std::process::exit(-1); } } @@ -302,9 +308,10 @@ 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 = client.open_file(datacenter, datastore, path).await?; + let config = vmx::VmConfig::parse(config, path).await.with_context(|| { + format!("error when parsing VM config: {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