From 811233563b432d1b16a2d2341c176b91d8c32558 Mon Sep 17 00:00:00 2001 From: Vince Buffalo Date: Thu, 24 Aug 2023 22:46:55 -0700 Subject: [PATCH] prettier warning message --- src/lib/data.rs | 2 +- src/lib/remote.rs | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/lib/data.rs b/src/lib/data.rs index 28810a5..4925260 100644 --- a/src/lib/data.rs +++ b/src/lib/data.rs @@ -502,7 +502,7 @@ impl DataCollection { e.insert(data_file); Ok(()) } else { - Err(anyhow!("File '{}' is already registered in the data manifest. \ + Err(anyhow!("File '{}' is already registered in the data manifest.\n\ If you wish to update the MD5 or metadata, use: sdf update FILE", &data_file.path)) } diff --git a/src/lib/remote.rs b/src/lib/remote.rs index ba0113d..1ccff7a 100644 --- a/src/lib/remote.rs +++ b/src/lib/remote.rs @@ -207,18 +207,24 @@ impl Remote { } pub fn authenticate_remote(remote: &mut Remote) -> Result<()> { - // Get they keys off disk + // Get the keys off disk let auth_keys = AuthKeys::new(); - #[allow(clippy::single_match)] + let error_message = |service_name: &str, token_name: &str| { + format!("Expected {} access token not found.\n\n\ + If you used 'sdf link', it should have saved this token in ~/.scidataflow_authkeys.yml.\n\ + You will need to re-add this key manually, by adding a line to this file like:\n\ + {}: ", service_name, token_name) + }; + match remote { Remote::FigShareAPI(ref mut fgsh_api) => { let token = auth_keys.keys.get("figshare").cloned() - .ok_or_else(|| anyhow::anyhow!("Expected figshare key not found"))?; + .ok_or_else(|| anyhow::anyhow!(error_message("FigShare", "figshare")))?; fgsh_api.set_token(token); }, Remote::ZenodoAPI(ref mut znd_api) => { let token = auth_keys.keys.get("zenodo").cloned() - .ok_or_else(|| anyhow::anyhow!("Expected figshare key not found"))?; + .ok_or_else(|| anyhow::anyhow!(error_message("Zenodo", "zenodo")))?; znd_api.set_token(token); }, // handle other Remote variants as necessary @@ -227,6 +233,7 @@ pub fn authenticate_remote(remote: &mut Remote) -> Result<()> { Ok(()) } + // Common enum for issue_request() methods of APIs #[derive(Debug)] pub enum RequestData {