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 error for no profiles found (new user) #303

Merged
merged 5 commits into from
Feb 23, 2021
Merged
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: 4 additions & 0 deletions crates/houston/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ pub enum HoustonProblem {
#[error("There is no profile named \"{0}\".")]
ProfileNotFound(String),

/// NoProfilesFound occurs When there are no profiles at all, often for new users
#[error("No config profiles found")]
NoConfigProfiles,

/// NoNonSensitiveConfigFound occurs when non-sensitive config can't be found for a profile.
#[error("No non-sensitive configuration found for profile \"{0}\".")]
NoNonSensitiveConfigFound(String),
Expand Down
3 changes: 3 additions & 0 deletions crates/houston/src/profile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,15 @@ impl Profile {
/// Loads and deserializes configuration from the file system for a
/// specific profile.
pub fn load(name: &str, config: &Config, opts: LoadOpts) -> Result<Profile, HoustonProblem> {
let profile_count = Profile::list(&config).unwrap_or_default().len();
if Profile::dir(name, config).exists() {
if opts.sensitive {
let sensitive = Sensitive::load(name, config)?;
return Ok(Profile { sensitive });
}
Err(HoustonProblem::NoNonSensitiveConfigFound(name.to_string()))
} else if profile_count == 0 {
Err(HoustonProblem::NoConfigProfiles)
} else {
Err(HoustonProblem::ProfileNotFound(name.to_string()))
}
Expand Down
1 change: 1 addition & 0 deletions src/error/metadata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ impl From<&mut anyhow::Error> for Metadata {
};
(suggestion, code)
}
HoustonProblem::NoConfigProfiles => (Some(Suggestion::NewUserNoProfiles), None),
HoustonProblem::ProfileNotFound(_) => (Some(Suggestion::ListProfiles), None),
HoustonProblem::TomlDeserialization(_)
| HoustonProblem::TomlSerialization(_)
Expand Down
6 changes: 6 additions & 0 deletions src/error/metadata/suggestion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub enum Suggestion {
Adhoc(String),
CheckKey,
ProperKey,
NewUserNoProfiles,
}

impl Display for Suggestion {
Expand Down Expand Up @@ -83,6 +84,11 @@ impl Display for Suggestion {
Suggestion::ProperKey => {
format!("Visit {} for more details on Apollo's API keys.", Cyan.normal().paint("https://go.apollo.dev/r/api-keys"))
}
Suggestion::NewUserNoProfiles => {
format!("It looks like you may be new here (we couldn't find any existing config profiles). To authenticate with Apollo Studio, run {}",
Cyan.normal().paint("rover config auth")
)
}
Suggestion::Adhoc(msg) => msg.to_string()

};
Expand Down
2 changes: 1 addition & 1 deletion src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Display for RoverError {
suggestion_descriptor_message.push(' ');
}
let suggestion_descriptor = Cyan.bold().paint(&suggestion_descriptor_message);
write!(formatter, "{} {}", suggestion_descriptor, suggestion)?;
writeln!(formatter, "{} {}", suggestion_descriptor, suggestion)?;
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 was mentioned by Jesse-

zsh prints a % after a command if it doesn't end with a newline

}
Ok(())
}
Expand Down