Skip to content

Commit

Permalink
greenlight: return credential errors in relevant code paths
Browse files Browse the repository at this point in the history
  • Loading branch information
JssDWt committed May 30, 2024
1 parent 13c3bc7 commit 9137078
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 4 additions & 4 deletions libs/sdk-core/src/greenlight/node_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl Greenlight {
// Query for the existing credentials
let mut parsed_credentials =
Self::get_node_credentials(config.network, &temp_signer, persister.clone())?
.ok_or(NodeError::generic("No credentials found"));
.ok_or(NodeError::credentials("No credentials found"));
if parsed_credentials.is_err() {
info!("No credentials found, trying to recover existing node");
parsed_credentials = match Self::recover(config.network, seed.clone()).await {
Expand Down Expand Up @@ -145,7 +145,7 @@ impl Greenlight {
None => Err(NodeError::generic("Failed to encrypt credentials")),
}
}
Err(_) => Err(NodeError::generic("Failed to get gl credentials")),
Err(_) => Err(NodeError::credentials("Failed to get gl credentials")),
}
}

Expand Down Expand Up @@ -397,12 +397,12 @@ impl Greenlight {
Some(decrypted_creds) => {
let credentials = Device::from_bytes(decrypted_creds.as_slice());
if credentials.cert.is_empty() {
Err(NodeError::generic("Unable to parse credentials"))
Err(NodeError::credentials("Unable to parse credentials"))
} else {
Ok(Some(credentials))
}
}
None => Err(NodeError::generic(
None => Err(NodeError::credentials(
"Failed to decrypt credentials, seed doesn't match existing node",
)),
}
Expand Down
4 changes: 4 additions & 0 deletions libs/sdk-core/src/node_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ pub enum NodeError {
}

impl NodeError {
pub(crate) fn credentials(err: &str) -> Self {
Self::Credentials(err.to_string())
}

pub(crate) fn generic(err: &str) -> Self {
Self::Generic(err.to_string())
}
Expand Down

0 comments on commit 9137078

Please sign in to comment.