apollographql / apollo-rs

Spec compliant GraphQL Tools in Rust.
Apache License 2.0
576 stars 45 forks source link

Many lexer errors do not have a location #731

Closed goto-bus-stop closed 3 months ago

goto-bus-stop commented 1 year ago

Description

Many errors emitted by the lexer do not set the error.index property, so they point to the start of the document by default.

Steps to reproduce

Input a GraphQL document with unexpected characters:

type Query {
  // Some invalid characters
  user: User
}

Expected result

Syntax errors point to the correct position

Actual result

rror: syntax error: Unexpected character "/"
   ╭─[q.graphql:1:1]
   │
 1 │ type Query {
   │ ┬
   │ ╰── Unexpected character "/"
───╯
Error: syntax error: Unexpected character "/"
   ╭─[q.graphql:1:1]
   │
 1 │ type Query {
   │ ┬
   │ ╰── Unexpected character "/"
───╯
SimonSapin commented 1 year ago

I’d be in favor of eventually removing the Error::new constructor that sets the index to zero, making the index always provided by the caller.