Skip to content

Commit

Permalink
Remove stack trace from parsing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Aug 23, 2023
1 parent f62d75c commit 31c7076
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1001,32 +1001,12 @@ const query;
const { code, stderr } = await runCommand();

expect(code).toBe(1);
expect(normalizeStacktracePath(stderr)).toMatchInlineSnapshot(`
expect(stderr).toMatchInlineSnapshot(`
[
"src/greeting.graphql",
"2:11 error GraphQLError: Syntax Error: Expected Name, found <EOF>.",
"at syntaxError (node_modules/graphql/error/syntaxError.js:15:10)",
"at Parser.expectToken (node_modules/graphql/language/parser.js:1397:40)",
"at Parser.parseName (node_modules/graphql/language/parser.js:108:24)",
"at Parser.parseField (node_modules/graphql/language/parser.js:347:30)",
"at Parser.parseSelection (node_modules/graphql/language/parser.js:337:14)",
"at Parser.many (node_modules/graphql/language/parser.js:1511:26)",
"at Parser.parseSelectionSet (node_modules/graphql/language/parser.js:320:24)",
"at Parser.parseOperationDefinition (node_modules/graphql/language/parser.js:248:26)",
"at Parser.parseDefinition (node_modules/graphql/language/parser.js:202:23)",
"at Parser.many (node_modules/graphql/language/parser.js:1511:26)",
"src/components/my-component.js",
"3:11 error SyntaxError: Missing initializer in const declaration. (3:11)",
"at instantiate (node_modules/@babel/parser/lib/index.js:64:32)",
"at constructor (node_modules/@babel/parser/lib/index.js:361:12)",
"at JSXParserMixin.raise (node_modules/@babel/parser/lib/index.js:3251:19)",
"at JSXParserMixin.parseVar (node_modules/@babel/parser/lib/index.js:13186:16)",
"at JSXParserMixin.parseVarStatement (node_modules/@babel/parser/lib/index.js:13017:10)",
"at JSXParserMixin.parseStatementContent (node_modules/@babel/parser/lib/index.js:12621:23)",
"at JSXParserMixin.parseStatementLike (node_modules/@babel/parser/lib/index.js:12535:17)",
"at JSXParserMixin.parseModuleItem (node_modules/@babel/parser/lib/index.js:12519:17)",
"at JSXParserMixin.parseBlockOrModuleBlockBody (node_modules/@babel/parser/lib/index.js:13106:36)",
"at JSXParserMixin.parseBlockBody (node_modules/@babel/parser/lib/index.js:13099:10)",
"✖ 2 errors",
]
`);
Expand Down Expand Up @@ -1084,7 +1064,7 @@ query {
const { code, stderr } = await runCommand();

expect(code).toBe(1);
expect(normalizeStacktracePath(stderr)).toMatchInlineSnapshot(`
expect(stderr).toMatchInlineSnapshot(`
[
"src/current-user-fragment.graphql",
"1:1 error Fragment named "CurrentUserFragment" already defined in: src/current-user-fragment2.graphql",
Expand All @@ -1098,16 +1078,6 @@ query {
"1:1 error Anonymous GraphQL operations are not supported. Please name your query.",
"src/syntax-error.graphql",
"2:11 error GraphQLError: Syntax Error: Expected Name, found <EOF>.",
"at syntaxError (node_modules/graphql/error/syntaxError.js:15:10)",
"at Parser.expectToken (node_modules/graphql/language/parser.js:1397:40)",
"at Parser.parseName (node_modules/graphql/language/parser.js:108:24)",
"at Parser.parseField (node_modules/graphql/language/parser.js:347:30)",
"at Parser.parseSelection (node_modules/graphql/language/parser.js:337:14)",
"at Parser.many (node_modules/graphql/language/parser.js:1511:26)",
"at Parser.parseSelectionSet (node_modules/graphql/language/parser.js:320:24)",
"at Parser.parseOperationDefinition (node_modules/graphql/language/parser.js:248:26)",
"at Parser.parseDefinition (node_modules/graphql/language/parser.js:202:23)",
"at Parser.many (node_modules/graphql/language/parser.js:1511:26)",
"✖ 6 errors",
]
`);
Expand Down Expand Up @@ -1139,12 +1109,6 @@ function base64(query: DocumentNode) {
return Buffer.from(print(query)).toString("base64");
}

function normalizeStacktracePath(stderr: string[]) {
return stderr.map((line) => {
return line.replace(/\{\{homedir\}\}\/.+?\/(node_modules)/, "$1");
});
}

interface ApolloCustomMatchers<R = void> {
toBeManifestWithOperations(operations: PersistedQueryManifestOperation[]): R;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/generate-persisted-query-manifest/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const ERROR_MESSAGES = {
)}".`;
},
parseError(error: Error) {
return error.stack ? error.stack : `${error.name}: ${error.message}`;
return `${error.name}: ${error.message}`;
},
};

Expand Down

0 comments on commit 31c7076

Please sign in to comment.