Skip to content

Commit a2c7ed4

Browse files
alex-statsigfacebook-github-bot
authored andcommitted
relay-compiler diagnostic errors logging improvements (#4574)
Summary: Couple of improvements to relay compiler error output to address issues from #4571 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) Pull Request resolved: #4574 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`. Reviewed By: alunyov Differential Revision: D52663262 Pulled By: captbaritone fbshipit-source-id: e2fcf98a3ace0a83aa73b2eaabeea10d1958b455
1 parent 0a9d473 commit a2c7ed4

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

compiler/crates/common/src/diagnostic.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,19 +225,19 @@ impl Diagnostic {
225225
let mut result = String::new();
226226
writeln!(
227227
result,
228-
"{message}: {location:?}",
228+
"{message}: {location}",
229229
message = &self.0.message,
230-
location = self.0.location
230+
location = self.0.location.source_location().path()
231231
)
232232
.unwrap();
233233
if !self.0.related_information.is_empty() {
234234
for (ix, related) in self.0.related_information.iter().enumerate() {
235235
writeln!(
236236
result,
237-
"[related {ix}] {message}:{location:?}",
237+
"[related {ix}] {message}:{location}",
238238
ix = ix + 1,
239239
message = related.message,
240-
location = related.location
240+
location = related.location.source_location().path()
241241
)
242242
.unwrap();
243243
}

compiler/crates/relay-compiler/src/errors.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,9 @@ pub enum ConfigValidationError {
229229
#[derive(Debug, Error)]
230230
pub enum BuildProjectError {
231231
#[error(
232-
"Validation errors:{}",
232+
"Validation errors: {} error(s) encountered above.",
233233
errors
234-
.iter()
235-
.map(|err| format!("\n - {}", err.print_without_source()))
236-
.collect::<Vec<_>>()
237-
.join("")
234+
.len()
238235
)]
239236
ValidationErrors {
240237
errors: Vec<Diagnostic>,

0 commit comments

Comments
 (0)