facebook / facebook/relay

[relay-compiler] Display a user friendly error when compilation fails trying to parse a unicode character in comments.

Open
#4,044 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Rust
Stars
19k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

### Summary
When the relay compiler fails to parse Unicode characters in comments, a hard-to-understand error is thrown.
Repro - https://github.com/relayjs/relay-examples/pull/238

### Suggestion
Display a more friendly error message similar to what is shown when we use Unicode characters in String Value.
Example
```
data/schema.graphql:22:22
21 │ todos(
22 │ status: String = "🐛"
│ ^
23 │ after: String

[ERROR] Compilation failed.
[ERROR] Unable to run relay compiler. Error details:
Failed to build:
- Validation errors:
- Unsupported character:data/schema.graphql:278:282

- String containing an invalid character:data/schema.graphql:277:278
```

P.S: It would be nice if the relay compiler supported Unicode characters in comments as noted in the [spec](https://spec.graphql.org/October2021/#note-3e8b0).

### Error Trace:
```$ relay-compiler
[INFO] [default] compiling...
thread 'main' panicked at 'internal error: entered unreachable code', crates/graphql-syntax/src/lexer.rs:169:40
stack backtrace:
0: 0x10090b981 - ::fmt::h428cf6d3383daa9c
1: 0x10092b70b - core::fmt::write::hcf88e896ec23e052
2: 0x10090383a - std::io::Write::write_fmt::h58c3052bb04c456d
3: 0x10090d215 - std::panicking::default_hook::{{closure}}::h99b76afd6b358916
4: 0x10090cdff - std::panicking::default_hook::hd7fbc9eda5da2259
5: 0x10090d900 - std::panicking::rust_panic_with_hook::h48eeb24de18c027c
6: 0x10090d374 - std::panicking::begin_panic_handler::{{closure}}::h1cb76dc2cf734090
7: 0x10090bdf7 - std::sys_common::backtrace::__rust_end_short_backtrace::h6ba95b68f495d865
8: 0x10090d30a - _rust_begin_unwind
9: 0x10099974f - core::panicking::panic_fmt::h91749835f0f98da6
10: 0x1009996a7 - core::panicking::panic::h2506d393f68a9da8
11: 0x1007cc998 - ::lex::goto163::h4f5f58549d0e8590
12: 0x1007bdea1 - graphql_syntax::parser::Parser::parse_token::h3c7ebb3ca4cc5ebf
13: 0x1007ba860 - graphql_syntax::parser::Parser::parse_identifier::hb55b4e3f6094f0c1
14: 0x1007b5fa8 - graphql_syntax::parser::Parser::parse_type_annotation::hd829ac3c0928a3f2
15: 0x1007b50a8 - graphql_syntax::parser::Parser::parse_fields_definition::hd5d254baea740a9f
16: 0x1007b1604 - graphql_syntax::parser::Parser::parse_type_system_definition::ha91f0162cc614300
17: 0x1007af9ee - graphql_syntax::parser::Parser::parse_schema_document::h37eddc9d11b2f34c
18: 0x1007bf558 - graphql_syntax::parse_schema_document::hf664e87d318e2e07
19: 0x1002f4b89 - schema::build_schema_with_extensions::h39af0c0680f1bddb
20: 0x10035a93a - relay_schema::build_schema_with_extensions::h712446a705faa493
21: 0x10042858d - relay_compiler::build_project::build_schema::build_schema::h4829e9b1086038cd
22: 0x10017a433 - relay_compiler::build_project::build_project::hbd5b992287782937
23: 0x100116087 - as rayon::iter::plumbing::Folder>::consume::h7db8015861c0f7fa
24: 0x100159f15 - rayon::iter::plumbing::Folder::consume_iter::hacfd0716540b269f
25: 0x1000b88c0 - rayon::iter::plumbing::bridge_producer_consumer::helper::h2e066357640b8e16
26: 0x1001140c2 - as rayon::iter::ParallelIterator>::drive_unindexed::hf1fff89f1da02748
27: 0x1000dd14e - rayon::iter::collect:: for alloc::vec::Vec>::par_extend::hdef75d239ae2891d
28: 0x1001b4b63 - as core::future::future::Future>::poll::h37dd0035c6c480e9
29: 0x1001c69a9 - relay::handle_compiler_command::{{closure}}::h0db99ecdce75180c
30: 0x1001b77e2 - as core::future::future::Future>::poll::h6e72441c09625aca
31: 0x10014731c - tokio::park::thread::CachedParkThread::block_on::hb38ba47d64a584d1
32: 0x1001b13e9 - tokio::runtime::thread_pool::ThreadPool::block_on::h1199d9f95b627222
33: 0x10018fbd9 - tokio::runtime::Runtime::block_on::h81308d61521fe7b8
34: 0x10020046e - relay::main::h3fbf7cd29d13ee38
35: 0x1001a1b26 - std::sys_common::backtrace::__rust_begin_short_backtrace::ha69bfecf8f427213
36: 0x10016b8cc - std::rt::lang_start::{{closure}}::h0a32ac5f44efc2bf
37: 0x10090b62f - std::rt::lang_start_internal::h240e1720b3cdfa5e
38: 0x1002005c9 - _main
error Command failed with exit code 101.```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.