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

fix: Error if the check workflow fails but all known tasks succeed #1280

Merged
merged 4 commits into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
20 changes: 20 additions & 0 deletions crates/rover-client/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ pub enum RoverClientError {
check_response: CheckResponse,
},

// While checking the proposed schema, the operations task (and also build task, if run) succeeded,
// but other check tasks failed.
#[error("{}", other_check_task_failure_msg(.has_build_task))]
OtherCheckTaskFailure {
has_build_task: bool,
target_url: String,
},

/// This error occurs when a user has a malformed Graph Ref
#[error("Graph IDs must be in the format <NAME> or <NAME>@<VARIANT>, where <NAME> can only contain letters, numbers, or the characters `-` or `_`, and must be 64 characters or less. <VARIANT> must be 64 characters or less.")]
InvalidGraphRef,
Expand Down Expand Up @@ -179,6 +187,18 @@ pub enum RoverClientError {
ChecksTimeoutError { url: Option<String> },
}

fn other_check_task_failure_msg(has_build_task: &bool) -> String {
let succeeding_tasks = if *has_build_task {
"Build and operations tasks".to_string()
} else {
"Operations task".to_string()
};
format!(
"{} succeeded, but other check tasks failed.",
succeeding_tasks
)
}

fn operation_check_error_msg(check_response: &CheckResponse) -> String {
let failure_count = check_response.get_failure_count();
let plural = match failure_count {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ fn get_check_response_from_data(
changes,
status,
graph_ref,
false,
core_schema_modified,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ fn get_check_response_from_data(
changes,
status,
graph_ref,
true,
core_schema_modified,
)
} else {
Expand Down
18 changes: 13 additions & 5 deletions crates/rover-client/src/shared/check_response.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::cmp::Ordering;
use std::fmt::{self, Display};
use std::str::FromStr;

Expand Down Expand Up @@ -31,6 +30,7 @@ impl CheckResponse {
changes: Vec<SchemaChange>,
result: ChangeSeverity,
graph_ref: GraphRef,
has_build_task: bool,
core_schema_modified: bool,
) -> Result<CheckResponse, RoverClientError> {
let mut failure_count = 0;
Expand All @@ -49,13 +49,21 @@ impl CheckResponse {
core_schema_modified,
};

match failure_count.cmp(&0) {
Ordering::Equal => Ok(check_response),
Ordering::Greater => Err(RoverClientError::OperationCheckFailure {
if failure_count > 0 {
return Err(RoverClientError::OperationCheckFailure {
graph_ref,
check_response,
});
}
match check_response.result {
ChangeSeverity::PASS => Ok(check_response),
ChangeSeverity::FAIL => Err(RoverClientError::OtherCheckTaskFailure {
has_build_task,
target_url: check_response.target_url.unwrap_or_else(||
// Note that graph IDs and variants don't need percent-encoding due to their regex restrictions.
Copy link
Contributor

Choose a reason for hiding this comment

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

you love to see it

format!("https://studio.apollographql.com/graph/{}/checks?variant={}", graph_ref.name, graph_ref.variant)
)
}),
Ordering::Less => unreachable!("Somehow encountered a negative number of failures."),
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/command/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,7 @@ mod tests {
ChangeSeverity::PASS,
graph_ref,
true,
true,
);
if let Ok(mock_check_response) = mock_check_response {
let actual_json: JsonOutput = RoverOutput::CheckResponse(mock_check_response).into();
Expand Down Expand Up @@ -891,6 +892,7 @@ mod tests {
],
ChangeSeverity::FAIL, graph_ref,
false,
false,
);

if let Err(operation_check_failure) = check_response {
Expand Down
2 changes: 2 additions & 0 deletions src/error/metadata/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub enum Code {
E033,
E034,
E035,
E036,
}

impl Display for Code {
Expand Down Expand Up @@ -89,6 +90,7 @@ impl Code {
(Code::E033, include_str!("./codes/E033.md").to_string()),
(Code::E034, include_str!("./codes/E034.md").to_string()),
(Code::E035, include_str!("./codes/E035.md").to_string()),
(Code::E036, include_str!("./codes/E036.md").to_string()),
];
contents.into_iter().collect()
}
Expand Down
1 change: 1 addition & 0 deletions src/error/metadata/codes/E036.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This check error occurs when the operations task (and build task, if run) have succeeded, but some other check task has failed. Please view the check in [Apollo Studio](https://studio.apollographql.com/) at the provided link to see the failure reason. You can read more about client checks [here](https://www.apollographql.com/docs/studio/schema-checks/).
9 changes: 9 additions & 0 deletions src/error/metadata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ impl From<&mut saucer::Error> for Metadata {
}),
Some(Code::E030),
),
RoverClientError::OtherCheckTaskFailure {
has_build_task: _,
target_url,
} => (
Some(Suggestion::FixOtherCheckTaskFailure {
target_url: target_url.clone(),
}),
Some(Code::E036),
),
RoverClientError::SubgraphIntrospectionNotAvailable => {
(Some(Suggestion::UseFederatedGraph), Some(Code::E007))
}
Expand Down
4 changes: 4 additions & 0 deletions src/error/metadata/suggestion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ pub enum Suggestion {
FixOperationsInSchema {
graph_ref: GraphRef,
},
FixOtherCheckTaskFailure {
target_url: String,
},
IncreaseClientTimeout,
IncreaseChecksTimeout {
url: Option<String>,
Expand Down Expand Up @@ -162,6 +165,7 @@ impl Display for Suggestion {
Suggestion::FixSubgraphSchema { graph_ref, subgraph } => format!("The changes in the schema you proposed for subgraph {} are incompatible with supergraph {}. See {} for more information on resolving build errors.", Yellow.normal().paint(subgraph.to_string()), Yellow.normal().paint(graph_ref.to_string()), Cyan.normal().paint("https://www.apollographql.com/docs/federation/errors/")),
Suggestion::FixCompositionErrors => format!("The subgraph schemas you provided are incompatible with each other. See {} for more information on resolving build errors.", Cyan.normal().paint("https://www.apollographql.com/docs/federation/errors/")),
Suggestion::FixOperationsInSchema { graph_ref } => format!("The changes in the schema you proposed are incompatible with graph {}. See {} for more information on resolving operation check errors.", Yellow.normal().paint(graph_ref.to_string()), Cyan.normal().paint("https://www.apollographql.com/docs/studio/schema-checks/")),
Suggestion::FixOtherCheckTaskFailure { target_url } => format!("See {} to view the failure reason for the check.", Cyan.normal().paint(target_url)),
Suggestion::IncreaseClientTimeout => "You can try increasing the timeout value by passing a higher value to the --client-timeout option.".to_string(),
Suggestion::IncreaseChecksTimeout {url} => format!("You can try increasing the timeout value by setting APOLLO_CHECKS_TIMEOUT_SECONDS to a higher value in your env. The default value is 300 seconds. You can also view the live check progress by visiting {}.", Cyan.normal().paint(url.clone().unwrap_or_else(|| "https://studio.apollographql.com".to_string()))),
Suggestion::FixChecksInput { graph_ref } => format!("Graph {} has no published schema or is not a composition variant. Please publish a schema or use a different variant.", Yellow.normal().paint(graph_ref.to_string())),
Expand Down