From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 22CC67B547 for ; Wed, 12 May 2021 12:06:53 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 0BFD5BC1D for ; Wed, 12 May 2021 12:06:23 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 803A3BC14 for ; Wed, 12 May 2021 12:06:22 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 4C7EC44FD2 for ; Wed, 12 May 2021 12:06:22 +0200 (CEST) From: Wolfgang Bumiller To: pbs-devel@lists.proxmox.com Date: Wed, 12 May 2021 12:06:18 +0200 Message-Id: <20210512100618.7526-1-w.bumiller@proxmox.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.017 Adjusted score from AWL reputation of From: address 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 Subject: [pbs-devel] [PATCH backup] acme: improve errors when account loading fails X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 May 2021 10:06:53 -0000 if the account does not exist, error with its name if file loading fails, the error includes the full path if the content fails to parse, show file & parse error and in each case mention that it's about loading the acme account file Signed-off-by: Wolfgang Bumiller --- src/acme/client.rs | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/acme/client.rs b/src/acme/client.rs index 91ef8b2a..28f277e9 100644 --- a/src/acme/client.rs +++ b/src/acme/client.rs @@ -4,7 +4,7 @@ use std::fs::OpenOptions; use std::io; use std::os::unix::fs::OpenOptionsExt; -use anyhow::format_err; +use anyhow::{bail, format_err}; use bytes::Bytes; use hyper::{Body, Request}; use nix::sys::stat::Mode; @@ -78,13 +78,25 @@ impl AcmeClient { /// Load an existing ACME account by name. pub async fn load(account_name: &AcmeAccountName) -> Result { - Self::load_path(account_path(account_name.as_ref())).await - } - - /// Load an existing ACME account by path. - async fn load_path(account_path: String) -> Result { - let data = tokio::fs::read(&account_path).await?; - let data: AccountData = serde_json::from_slice(&data)?; + let account_path = account_path(account_name.as_ref()); + let data = match tokio::fs::read(&account_path).await { + Ok(data) => data, + Err(err) if err.kind() == io::ErrorKind::NotFound => { + bail!("acme account '{}' does not exist", account_name) + } + Err(err) => bail!( + "failed to load acme account from '{}' - {}", + account_path, + err + ), + }; + let data: AccountData = serde_json::from_slice(&data).map_err(|err| { + format_err!( + "failed to parse acme account from '{}' - {}", + account_path, + err + ) + })?; let account = Account::from_parts(data.location, data.key, data.account); -- 2.20.1