Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some more user feedback #97

Merged
merged 9 commits into from
Mar 14, 2022
4 changes: 2 additions & 2 deletions agent/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ pub enum Error {
AuthorizationFailed,
UnableToParseResponse,
UrlDoesNotExist,
InternalServerError,
UnknownResponseStatusCode(String),
InternalServerError(u16),
UnreachableUrl,
HttpServiceUnavailable,
}
Expand All @@ -21,8 +21,8 @@ impl Display for Error {
Error::AuthorizationFailed => write!(f, "Failed to authorize. Either the wrong or no api-key is provided."),
Error::UnableToParseResponse => write!(f, "Unable to parse the response from the server. Is the cloudagent the correct version?"),
Error::UrlDoesNotExist => write!(f, "Path does not exist on endpoint. This can happen when querying by id and the id is not valid."),
Error::InternalServerError => write!(f, "Internal Server Error!"),
Error::UnknownResponseStatusCode(msg) => write!(f, "Received unknown status code from the server. Endpoint is likely incorrect. If the endpoint is correct, please report this error at https://github.com/animo/aries-cli/issues/new \nAdditional info: {}", msg),
Error::InternalServerError(status) => write!(f, "Internal Server Error (status code: {})!", status),
Error::UnreachableUrl => write!(f, "Provided url is unreachable. Is the provided endpoint valid?"),
Error::HttpServiceUnavailable => write!(f, "Cloudagent is currently unavailable. Are you sure the agent is online?")

Expand Down
2 changes: 2 additions & 0 deletions cli/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::fmt::{Display, Formatter};

#[derive(Debug)]
pub enum Error {
CannotReadConfigurationFile,
InvalidConfigurationPath,
InvalidConfigurationStructure,
InvalidEnvironment,
Expand All @@ -21,6 +22,7 @@ pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Error::CannotReadConfigurationFile => write!(f, "Cannot not read configuration file. Try initializing first using: `aries-cli configuration initialize`."),
Error::InvalidConfigurationPath => write!(f, "Invalid configuration path."),
Error::InvalidEnvironment => write!(f, "Invalid environment."),
Error::NoEndpointSupplied => write!(f, "No endpoint supplied. Supply an endpoint either via `--endpoint` or via `--config`."),
Expand Down
21 changes: 18 additions & 3 deletions cli/src/modules/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use crate::error;
use crate::error::Result;
use crate::utils::config::{get_config_path, Configurations};
use clap::{Args, Subcommand};
use log::info;
use colored::*;
use log::{debug, info};
use std::fs;
use std::path::Path;

Expand All @@ -23,10 +24,24 @@ pub async fn parse_configuration_args(options: &ConfigurationOptions) -> Result<
match options.commands {
ConfigurationSubcommands::Initialize => {
initialize(&config_path)?;
info!("Initialized the configuration!");
info!(
"{} configuration file at {}.",
"Initialised".cyan(),
config_path.display()
jl-animo marked this conversation as resolved.
Show resolved Hide resolved
);
Ok(())
}
ConfigurationSubcommands::View => view(&config_path),
ConfigurationSubcommands::View => {
debug!(
"Loaded configuration from {}",
String::from(config_path.to_str().unwrap()).bold()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String::from is not required here right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so that we can use bold()

);

view(&config_path).map_err(|err| {
debug!("Failed to read config file: {}", err);
error::Error::CannotReadConfigurationFile.into()
})
}
jl-animo marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
14 changes: 10 additions & 4 deletions cli/src/modules/connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,19 @@ pub async fn parse_connection_args(
};
agent.create_invitation(options).await.map(|response| {
loader.stop();
info!(
"{}",
format!(
"{} invite with connection id: {}\n",
"Created".green(),
response.connection_id,
)
);
if *qr {
info!(
"{}",
format!("{}: {}", "Connection id".green(), response.connection_id)
);
info!("Scan this QR code to accept the invitation:\n");
print_qr_code(response.invitation_url).unwrap();
} else {
info!("Another agent can use this URL to accept your invitation:\n");
info!("{}", response.invitation_url)
}
})
Expand Down
7 changes: 6 additions & 1 deletion cli/src/modules/credential_definition.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use agent::modules::credential_definition::CredentialDefinitionModule;
use clap::{Args, Subcommand};
use colored::*;
use log::{debug, info};
use serde_json::json;

Expand Down Expand Up @@ -54,7 +55,11 @@ pub async fn parse_credential_definition_args(
agent.create(schema_id.to_string()).await.map(|cred_def| {
loader.stop();
copy!("{}", cred_def.credential_definition_id);
info!("{}", cred_def.credential_definition_id);
info!(
"{} credential definition with id: {}.",
"Created".green(),
cred_def.credential_definition_id
)
})
}
},
Expand Down
2 changes: 1 addition & 1 deletion cloudagent-python/src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl CloudAgent {
// TODO: This response is quite ugly. Is it only used at cred_def_id?
422 => Err(res.text().await?.into()),
503 => Err(Error::HttpServiceUnavailable.into()),
500..=599 => Err(Error::InternalServerError.into()),
500..=599 => Err(Error::InternalServerError(res.status().as_u16()).into()),
_ => Err(Error::UnknownResponseStatusCode(res.text().await?).into()),
}
}
Expand Down