Skip to content

Commit

Permalink
relay-compiler diagnostic errors logging improvements
Browse files Browse the repository at this point in the history
1. Update diagnostic.print_without_source() to no longer include character ranges since the formatting of startchar:endchar doesnt match the standard expectation of linenumber:character (and thus editors will interpret it wrong)
2. Updated the ValidationErrors to no longer enumerate all errors, and instead show the count (since the actual errors are shown above anyway)

# Test Plan

Confirmed the new formatting of .print_without_source() is correct with no character ranges (tested via ValidationError since I'm not sure how to generate a DiagnosticsError, but this will no longer be triggered due to the summarization change):
```
[INFO] Querying files to compile...
[INFO] [default] compiling...
[ERROR] Error: ✖︎ The type `CustomMetric` has no field `test`.
See https://relay.dev/docs/error-reference/unknown-field/

  client/components/console/metrics_catalog/MetricDefinitionDebugDialog.tsx:20:7
   19 │       configuration_json
   20 │       test
      │       ^^^^
   21 │     }

[ERROR] Compilation failed.
[ERROR] Unable to run relay compiler. Error details:
Failed to build:
 - Validation errors:
 - The type `CustomMetric` has no field `test`.
See https://relay.dev/docs/error-reference/unknown-field/: client/components/console/metrics_catalog/MetricDefinitionDebugDialog.tsx
```

Confirmed the count shows instead of the individual errors now:
```
[INFO] Querying files to compile...
[INFO] [default] compiling...
[ERROR] Error: ✖︎ The type `CustomMetric` has no field `test`.
See https://relay.dev/docs/error-reference/unknown-field/

  client/components/console/metrics_catalog/MetricDefinitionDebugDialog.tsx:20:7
   19 │       configuration_json
   20 │       test
      │       ^^^^
   21 │     }

[ERROR] Compilation failed.
[ERROR] Unable to run relay compiler. Error details:
Failed to build:
 - Validation errors: 1 error(s) encountered above.

```

Also confirmed that config errors still showed up correctly:
```
[ERROR] Config `/Users/alex/dev/statsig/console/relay.config.js` is invalid:
 - The `schema` configured for project `default` does not exist at `./server/lib/graphql/schedma.graphql`.
  • Loading branch information
alex-statsig committed Jan 10, 2024
1 parent 13304c2 commit 4ab3234
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
8 changes: 4 additions & 4 deletions compiler/crates/common/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,19 +225,19 @@ impl Diagnostic {
let mut result = String::new();
writeln!(
result,
"{message}: {location:?}",
"{message}: {location}",
message = &self.0.message,
location = self.0.location
location = self.0.location.source_location().path()
)
.unwrap();
if !self.0.related_information.is_empty() {
for (ix, related) in self.0.related_information.iter().enumerate() {
writeln!(
result,
"[related {ix}] {message}:{location:?}",
"[related {ix}] {message}:{location}",
ix = ix + 1,
message = related.message,
location = related.location
location = related.location.source_location().path()
)
.unwrap();
}
Expand Down
7 changes: 2 additions & 5 deletions compiler/crates/relay-compiler/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,9 @@ pub enum ConfigValidationError {
#[derive(Debug, Error)]
pub enum BuildProjectError {
#[error(
"Validation errors:{}",
"Validation errors: {} error(s) encountered above.",
errors
.iter()
.map(|err| format!("\n - {}", err.print_without_source()))
.collect::<Vec<_>>()
.join("")
.len()
)]
ValidationErrors {
errors: Vec<Diagnostic>,
Expand Down

0 comments on commit 4ab3234

Please sign in to comment.