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

Relay Compiler outputted file links - bad format for VSCode #4571

Closed
alex-statsig opened this issue Jan 9, 2024 · 8 comments
Closed

Relay Compiler outputted file links - bad format for VSCode #4571

alex-statsig opened this issue Jan 9, 2024 · 8 comments

Comments

@alex-statsig
Copy link
Contributor

alex-statsig commented Jan 9, 2024

When running the relay compiler with errors, theres a few problems with the outputted erroring filepaths. They are not critical or "wrong", but cause inconvenience when attempting to open the problematic line (especially in vscode). Here's an example output:

[ERROR] Compilation failed.
[ERROR] Unable to run relay compiler. Error details: 
Failed to build:
 - Validation errors:
 - The type `Company` has no field `metric`. Did you mean `metrics`?:client/components/console/metrics_catalog/MetricPageInsightsCard.tsx:495:501
  1. Theres no space between "Did you mean?" and the file link. This causes vs-code to think the filepath starts with the "?", so cmd-clicking the file in terminal fails
  2. Theres a colon before the path; I'm not sure why this is here (to indicate its relative to the root?), but again it is included in the path opened by VSCode upon cmd-clicking, causing it to fail to find any files
  3. The numbers after the path appear to be character indices within the file, whereas vscode expects the format <path>:<linenumber>:<character_index_within_line>. I'm not sure how standard this format is, but it would be very convenient within vscode at least to adopt this format.
@captbaritone
Copy link
Contributor

This is great feedback thank you! I think the relevant code is here: https://github.com/facebook/relay/blob/main/compiler/crates/graphql-cli/src/diagnostic_printer.rs#L89

Would you be interested in opening a pull request?

@alex-statsig
Copy link
Contributor Author

alex-statsig commented Jan 9, 2024

It looks like this actually coming from somewhere else:
https://github.com/facebook/relay/blob/main/compiler/crates/common/src/diagnostic.rs#L226-L232

which calls into Location's toString: https://github.com/facebook/relay/blob/main/compiler/crates/common/src/location.rs#L86C3-L86C3

I'll put up a PR to fix the missing space, but converting the character span to line numbers seems a bit more involved, as I'm not sure the right information is being passed around to this Diagnostics object from a ton of callsites (in the code you linked, it actually is handled correctly by source.to_span_range(location.span()), but the source is not available here).

I'm still open to helping contribute that part, but it seems so much more involved that I would want a sanity check on the approach (adding location_range to DiagnosticsData)

alex-statsig added a commit to alex-statsig/relay that referenced this issue Jan 9, 2024
A space was missing between the error message and location in Diagnostic.print_without_source, which made it harder to open the file from terminal output with tools like vscode.

See facebook#4571

# Test Plan

Confirmed that now the path is outputted in a format that vscode can parse out:
```
[ERROR] Compilation failed.
[ERROR] Unable to run relay compiler. Error details:
Failed to build:
 - Validation errors:
 - The type `Company` has no field `metric`. Did you mean `metrics`?
See https://relay.dev/docs/error-reference/unknown-field/: client/components/console/pulse/details_dialog/PulseMetricDetailsDialog.tsx:465:471
```

Note that the line range is still incorrect (it is using the character span instead of linenumber:character), but this seems much trickier to fix.
facebook-github-bot pushed a commit that referenced this issue Jan 9, 2024
Summary:
Fix missing space in diagnostic location print

A space was missing between the error message and location in Diagnostic.print_without_source, which made it harder to open the file from terminal output with tools like vscode.

See #4571

Pull Request resolved: #4573

Test Plan:
Confirmed that now the path is outputted in a format that vscode can parse out:
```
[ERROR] Compilation failed.
[ERROR] Unable to run relay compiler. Error details:
Failed to build:
 - Validation errors:
 - The type `Company` has no field `metric`. Did you mean `metrics`?
See https://relay.dev/docs/error-reference/unknown-field/: client/components/console/pulse/details_dialog/PulseMetricDetailsDialog.tsx:465:471
```

Note that the line range is still incorrect (it is using the character span instead of linenumber:character), but this seems much trickier to fix.

Reviewed By: monicatang

Differential Revision: D52635842

Pulled By: captbaritone

fbshipit-source-id: fabc0aadb1b72deac2da377a44dd46afed46be60
@captbaritone
Copy link
Contributor

I see. This is just the location information at the bottom of the CLI output which summarizes the errors emitted above? Do you have nicely formatted diagnostics above with the correct line numbers?

@alex-statsig
Copy link
Contributor Author

alex-statsig commented Jan 9, 2024

I see. This is just the location information at the bottom of the CLI output which summarizes the errors emitted above? Do you have nicely formatted diagnostics above with the correct line numbers?

Ah yeah I do, and that seems to show the correct ranges / format. In my case I had ~20 validation errors and missed the section above. Is there a reason to output the individual errors again at the bottom with worse formatting? Are some errors only listed in the bottom summary? Perhaps that section should just say N Validation errors encountered above or something.

Thanks a ton for the quick responses and help tracking this down btw!

@captbaritone
Copy link
Contributor

I think the report at the bottom serves two purposes. It serves as a terser summary of all the encountered errors, and it also includes non-diagnostic errors such as config errors, etc..

I think replacing the diagnostics that appear here with a message that just includes the count does seem more reasonable.

@captbaritone
Copy link
Contributor

I think the two places we build those lists are:

@captbaritone
Copy link
Contributor

Additionally, I'd be open to a PR that just removes the location information when printing without source. I think it's strictly worse to include misleading information than no information.

facebook-github-bot pushed a commit that referenced this issue Jan 11, 2024
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
@alex-statsig
Copy link
Contributor Author

#4573 and #4574 both addressed pieces of this, seems resolved now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants