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

[Merged by Bors] - docs: improve hub credential error message #3614

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion crates/fluvio-cli/src/client/hub/connector/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ impl ConnectorHubDownloadOpts {
let data = fluvio_hub_util::get_package(&url, &access)
.await
.map_err(|err| {
CliError::HubError(format!("downloading {package_name} failed\nServer: {err}"))
CliError::HubError(format!(
"downloading {package_name} failed\nHub error: {err}"
))
})?;

std::fs::write(file_path, data).map_err(|err| {
Expand Down
14 changes: 8 additions & 6 deletions crates/fluvio-hub-protocol/src/infinyon_tok.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type InfinyonRemote = String;

#[derive(thiserror::Error, Debug)]
pub enum InfinyonCredentialError {
#[error("Read error {0}")]
#[error("{0}")]
Read(String),

#[error("unable to parse credentials")]
Expand Down Expand Up @@ -69,18 +69,20 @@ impl Credentials {
/// Try to load credentials from disk
fn try_load<P: AsRef<Path>>(base_path: P) -> Result<Self, InfinyonCredentialError> {
let current_login_path = base_path.as_ref().join(CURRENT_LOGIN_FILE_NAME);
let cfg_path = fs::read_to_string(&current_login_path).map_err(|_| {
let strpath = current_login_path.to_string_lossy().to_string();
InfinyonCredentialError::Read(strpath)
let cfg_path = fs::read_to_string(current_login_path).map_err(|_| {
InfinyonCredentialError::Read(
"no access credentials, try 'fluvio cloud login'".to_owned(),
)
})?;
let cred_path = base_path.as_ref().join(cfg_path);
Self::load(&cred_path)
}

fn load(cred_path: &Path) -> Result<Self, InfinyonCredentialError> {
let file_str = fs::read_to_string(cred_path).map_err(|_| {
let strpath = cred_path.to_string_lossy().to_string();
InfinyonCredentialError::Read(strpath)
InfinyonCredentialError::Read(
"no access credentials, try 'fluvio cloud login'".to_owned(),
)
})?;
let creds: Credentials = toml::from_str(&file_str)
.map_err(|_| InfinyonCredentialError::UnableToParseCredentials)?;
Expand Down