Skip to content

Commit

Permalink
Extend error message for parse/validation errors on startup, fixes #3681
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop committed Sep 7, 2023
1 parent 6f1a997 commit 525f376
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions apollo-router/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,9 @@ pub(crate) enum SchemaError {
UrlParse(String, http::uri::InvalidUri),
/// Could not find an URL for subgraph {0}
MissingSubgraphUrl(String),
/// GraphQL parser error(s).
/// GraphQL parser error: {0}
Parse(ParseErrors),
/// GraphQL parser or validation error(s).
/// GraphQL validation error: {0}
Validate(ValidationErrors),
/// Api error(s): {0}
Api(String),
Expand All @@ -526,11 +526,16 @@ pub(crate) struct ParseErrors {
impl std::fmt::Display for ParseErrors {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut errors = self.errors.iter();
if let Some(error) = errors.next() {
write!(f, "{}", error.message())?;
for (i, error) in errors.by_ref().take(5).enumerate() {
if i > 0 {
write!(f, "\n")?;
}
// TODO(@goto-bus-stop): display line/column once that is exposed from apollo-rs
write!(f, "at index {}: {}", error.index(), error.message())?;
}
for error in errors {
write!(f, "\n{}", error.message())?;
let remaining = errors.count();
if remaining > 0 {
write!(f, "\n...and {remaining} other errors")?;
}
Ok(())
}
Expand All @@ -546,10 +551,10 @@ impl std::fmt::Display for ValidationErrors {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut errors = self.errors.iter();
if let Some(error) = errors.next() {
write!(f, "{}", error.data)?;
write!(f, "at index {}: {}", error.location.offset(), error.data)?;
}
for error in errors {
write!(f, "\n{}", error.data)?;
write!(f, "\nat index {}: {}", error.location.offset(), error.data)?;
}
Ok(())
}
Expand Down

0 comments on commit 525f376

Please sign in to comment.