Skip to content

Commit

Permalink
add error suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
lrlna committed May 11, 2021
1 parent 7e0c426 commit 1a86858
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion installers/npm/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions src/command/subgraph/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use ansi_term::Colour::Red;
use serde::Serialize;
use structopt::StructOpt;

use crate::Result;
use rover_client::query::subgraph::check;
use crate::{anyhow, error::RoverError, Result, Suggestion};
use rover_client::query::{config::is_federated, subgraph::check};

use crate::command::RoverStdout;
use crate::utils::client::StudioClientConfig;
Expand Down Expand Up @@ -76,13 +76,13 @@ impl Check {

// We don't want to run subgraph check on a non-federated graph, so
// return an error and recommend running graph check instead.
if !federated_response.result && !self.convert {
return Err(RoverError::new(anyhow!(
"Not able to run subgraph check on a non-federated graph."
)));
if !federated_response.result {
let err = anyhow!("Not able to run subgraph check on a non-federated graph.");
let mut err = RoverError::new(err);
err.set_suggestion(Suggestion::UseFederatedGraph);
return Err(err);
}


let partial_schema = check::check_partial_schema_query::PartialSchemaInput {
sdl: Some(sdl),
// we never need to send the hash since the back end computes it from SDL
Expand Down
22 changes: 13 additions & 9 deletions src/command/subgraph/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ use ansi_term::Colour::{Cyan, Red, Yellow};
use serde::Serialize;
use structopt::StructOpt;

use crate::utils::{
client::StudioClientConfig,
git::GitContext,
loaders::load_schema_from_flag,
parsers::{parse_graph_ref, parse_schema_source, GraphRef, SchemaSource},
};
use crate::{anyhow, Result};
use crate::{command::RoverStdout, error::RoverError};
use crate::{
utils::{
client::StudioClientConfig,
git::GitContext,
loaders::load_schema_from_flag,
parsers::{parse_graph_ref, parse_schema_source, GraphRef, SchemaSource},
},
Suggestion,
};

use rover_client::query::{
config::is_federated,
Expand Down Expand Up @@ -84,9 +87,10 @@ impl Publish {
// Error here if no --convert flag is passed _and_ the current context
// is non-federated. Add a suggestion to require a --convert flag.
if !federated_response.result && !self.convert {
return Err(RoverError::new(anyhow!(
"Could not publish a subgraph to a non-federated graph."
)));
let err = anyhow!("Could not publish a subgraph to a non-federated graph.");
let mut err = RoverError::new(err);
err.set_suggestion(Suggestion::ConvertGraphToSubgraph);
return Err(err);
}

let publish_response = publish::run(
Expand Down
4 changes: 3 additions & 1 deletion src/error/metadata/suggestion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub enum Suggestion {
ProperKey,
NewUserNoProfiles,
CheckServerConnection,
ConvertGraphToSubgraph,
}

impl Display for Suggestion {
Expand Down Expand Up @@ -124,7 +125,8 @@ impl Display for Suggestion {
)
}
Suggestion::Adhoc(msg) => msg.to_string(),
Suggestion::CheckServerConnection => "Make sure the endpoint accepting connections is spelled correctly".to_string()
Suggestion::CheckServerConnection => "Make sure the endpoint accepting connections is spelled correctly".to_string(),
Suggestion::ConvertGraphToSubgraph => "If you are sure you want to convert a non-federated graph to a subgraph, you can re-run the same command with a `--convert` flag.".to_string(),


};
Expand Down

0 comments on commit 1a86858

Please sign in to comment.