graphql-java-tools icon indicating copy to clipboard operation
graphql-java-tools copied to clipboard

Wrong Line Numbers in Parsing Errors

Open mxmp210 opened this issue 5 years ago • 5 comments

I was trying to implement Relay / Connection example, accidentally I made a mistake in schema file and console was giving parsing errors. It looked something like this :

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [graphql.kickstart.tools.SchemaParser]: Factory method 'schemaParser' threw exception; nested exception is graphql.parser.InvalidSyntaxException: Invalid Syntax : offending token '(' at line 9 column 17

My Schema Contains two root functions

type Query {
    suppliers(name: String, first: Int, after: String): SupplierConnection @connection(for: "Supplier")
    components(name: String, first: Int, after: String): ComponentConnection @connection(for: "Component")
}
....

While the error was on line 2, column 19 for not having space between argument and type, it was impossible to identify where the problem persisted because of not readable error outputs.

I know this is an old issue and needs reworks, and documentation assumes many things that user would know before starting, Is there any way to format errors at-least right so that it can be helpful?

mxmp210 avatar Apr 14 '20 11:04 mxmp210

How do you pass the schema into SchemaParser?

vojtapol avatar Apr 14 '20 19:04 vojtapol

How do you pass the schema into SchemaParser?

It is picked up by graphql-kickstart from .graphqls files in resources. I managed to find error in schema, it's not the problem, the problem is, if the schema is having minor errors like having spaces or typing mistake, line number would be completely different, making it almost impossible to find from looking at error code.

mxmp210 avatar Apr 17 '20 06:04 mxmp210

Absolutely, we will look into this.

vojtapol avatar Apr 17 '20 19:04 vojtapol

Just had this error in a project. The problem is that the SchemaParser interprets all .graphqls files as a single file, that way, the column that is pointed is precise, but not the line, as it counts all the lines from other files parsed before, e.g., the line in which the error occurs is the line from the file plus an offset of all the lines already parsed from previous .graphql files.

Raf98 avatar Jan 12 '22 22:01 Raf98

Just had this error in a project. The problem is that the SchemaParser interprets all .graphqls files as a single file, that way, the column that is pointed is precise, but not the line, as it counts all the lines from other files parsed before, e.g., the line in which the error occurs is the line from the file plus an offset of all the lines already parsed from previous .graphql files.

Agreed, although whole point of stack trace is to get back to origin. Giving lines in internal in memory file would be misleading as complex schemas would contain multiple files and tracing them would be very hard from given information.

This issue is stalled for so long already.

mxmp210 avatar Jan 22 '22 19:01 mxmp210