* [pbs-devel] [PATCH backup] acme: improve errors when account loading fails
@ 2021-05-12 10:06 Wolfgang Bumiller
2021-05-12 10:23 ` [pbs-devel] applied: " Thomas Lamprecht
0 siblings, 1 reply; 2+ messages in thread
From: Wolfgang Bumiller @ 2021-05-12 10:06 UTC (permalink / raw)
To: pbs-devel
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 <w.bumiller@proxmox.com>
---
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, anyhow::Error> {
- 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<Self, anyhow::Error> {
- 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
^ permalink raw reply [flat|nested] 2+ messages in thread
* [pbs-devel] applied: [PATCH backup] acme: improve errors when account loading fails
2021-05-12 10:06 [pbs-devel] [PATCH backup] acme: improve errors when account loading fails Wolfgang Bumiller
@ 2021-05-12 10:23 ` Thomas Lamprecht
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Lamprecht @ 2021-05-12 10:23 UTC (permalink / raw)
To: Proxmox Backup Server development discussion, Wolfgang Bumiller
On 12.05.21 12:06, Wolfgang Bumiller wrote:
> 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 <w.bumiller@proxmox.com>
> ---
> src/acme/client.rs | 28 ++++++++++++++++++++--------
> 1 file changed, 20 insertions(+), 8 deletions(-)
>
>
applied, thanks!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-05-12 10:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-12 10:06 [pbs-devel] [PATCH backup] acme: improve errors when account loading fails Wolfgang Bumiller
2021-05-12 10:23 ` [pbs-devel] applied: " Thomas Lamprecht
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox