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

Better handling of syntax errors #345

Merged
merged 8 commits into from
Aug 23, 2023
Merged

Better handling of syntax errors #345

merged 8 commits into from
Aug 23, 2023

Conversation

jerelmiller
Copy link
Member

@jerelmiller jerelmiller commented Aug 23, 2023

When encountering a error while parsing the source file for GraphQL query strings (such as a syntax error), it was difficult to determine which file caused the error.

This PR adds a couple additional improvements:

  • Reports the error in a similar way as other errors, showing the filename and location of the error
  • Allows syntax errors to be reported alongside other errors, rather than halting the program on the first syntax error. This means that if multiple files have syntax errors, all of them will be displayed in the error output.

Before

$ npx generate-persisted-query-manifest
/Users/jerelmiller/code/apollo-utils/node_modules/@babel/parser/lib/index.js:64
}, descriptor)), Object.assign(new constructor(), properties));
                               ^

SyntaxError: Missing initializer in const declaration. (3:11)
    at instantiate (/Users/jerelmiller/code/apollo-utils/node_modules/@babel/parser/lib/index.js:64:32)
    at constructor (/Users/jerelmiller/code/apollo-utils/node_modules/@babel/parser/lib/index.js:361:12)
    at JSXParserMixin.raise (/Users/jerelmiller/code/apollo-utils/node_modules/@babel/parser/lib/index.js:3251:19)
    at JSXParserMixin.parseVar (/Users/jerelmiller/code/apollo-utils/node_modules/@babel/parser/lib/index.js:13186:16)
    at JSXParserMixin.parseVarStatement (/Users/jerelmiller/code/apollo-utils/node_modules/@babel/parser/lib/index.js:13017:10)
    at JSXParserMixin.parseStatementContent (/Users/jerelmiller/code/apollo-utils/node_modules/@babel/parser/lib/index.js:12621:23)
    at JSXParserMixin.parseStatementLike (/Users/jerelmiller/code/apollo-utils/node_modules/@babel/parser/lib/index.js:12535:17)
    at JSXParserMixin.parseModuleItem (/Users/jerelmiller/code/apollo-utils/node_modules/@babel/parser/lib/index.js:12519:17)
    at JSXParserMixin.parseBlockOrModuleBlockBody (/Users/jerelmiller/code/apollo-utils/node_modules/@babel/parser/lib/index.js:13106:36)
    at JSXParserMixin.parseBlockBody (/Users/jerelmiller/code/apollo-utils/node_modules/@babel/parser/lib/index.js:13099:10) {
  code: 'BABEL_PARSER_SYNTAX_ERROR',
  reasonCode: 'DeclarationMissingInitializer',
  loc: Position { line: 3, column: 11, index: 50 },
  pos: [Getter/Setter]
}

Node.js v20.4.0

After

$ npx generate-persisted-query-manifest
src/bad.graphql
   3:1  error  GraphQLError: Syntax Error: Expected Name, found <EOF>.

src/test.js
  3:11  error  SyntaxError: Missing initializer in const declaration. (3:11)

✖ 2 errors

@changeset-bot
Copy link

changeset-bot bot commented Aug 23, 2023

🦋 Changeset detected

Latest commit: decef30

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@apollo/generate-persisted-query-manifest Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codesandbox-ci
Copy link

codesandbox-ci bot commented Aug 23, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Base automatically changed from cli-testing-setup to main August 23, 2023 19:43
@jerelmiller jerelmiller merged commit 145836c into main Aug 23, 2023
8 checks passed
@jerelmiller jerelmiller deleted the handle-syntax-errors branch August 23, 2023 20:02
@github-actions github-actions bot mentioned this pull request Aug 23, 2023
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

Successfully merging this pull request may close these issues.

2 participants