-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
#5064 Display detailed errors from CLI #6921
Conversation
🦋 Changeset detectedLatest commit: 5a76e5c The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/theguild/graphql-code-generator/7gxSAUjnrLwovUb9PsL2uzLQMAce |
Hey @jlmessenger, could you please provide a minimal reproduction for the "Something went wrong" error message? I was trying to reproduce it locally, but could not figure it out. I just wanna make sure we are actually addressing a reproducible issue with this PR! |
Actually, I was able to reproduce this issue accidentally: it('Should sort the input schema', async () => {
const nonSortedSchema = /* GraphQL */ `
type Query {
d: String
z: String
a: String
}
type User {
aa: String
a: String
}
type A {
s: String
b: String
}
`;
const output = await executeCodegen({
schema: [nonSortedSchema],
generates: {
'out1.graphql': {
plugins: ['schema-ast'],
},
},
config: {
sort: true,
},
});
expect(output.length).toBe(1);
expect(output[0].content).toBeSimilarStringTo(/* GraphQL */ `
type A {
b: String
s: String
}
type Query {
a: String
d: String
z: String
}
type User {
a: String
aa: String
}
`);
});
it('Handles weird errors due to invalid schema', async () => {
const schema = /* GraphQL */ `
type Query {
brrrt:1
}
`;
await executeCodegen({
schema: [schema],
generates: {
'out1.graphql': {
plugins: ['schema-ast'],
},
},
});
}); I wonder whether |
@n1ru4l - Yes, it was triggering The actual schema tools are returning well formatted errors. However, This initial solution prints out the details of all entries in |
@jlmessenger Instead of doing this in
That way also the programmatic usage will yield useable error messages. Also, we need failing tests for progressing this further. @jlmessenger Can you please continue with that? |
Hi @n1ru4l - I want to ensure I understand your preferred approach before I rework the commit.
Draft Proposal: Update the following area of
try {
await listr.run();
} catch (err) {
if (isListrError(err)) {
if (err.errors.length === 1) {
throw err.errors[0]!; // only one error, so re-throw it
}
// Multiple errors, so unpack into a single DetailedError
const allErrs = err.errors.map(subErr => isDetailedError(errItem)
? `${subErr.message} for "${subErr.source}"${subErr.details}`
: subErr.message || subErr.toString()
);
const newErr = new DetailedError(`${err.message}${allErrs.join("\n\n")}`);
// Best-effort to all stack traces for debugging
newErr.stack = `${newErr.stack}\n\n${err.errors.map(subErr => subErr.stack).join("\n\n")}`;
throw newErr;
}
throw err;
} The above example assumes a type-guard function to detect and cast type CompositeError = Error | DetailedError;
type ListrError = Error & { errors: CompositeError[] };
function isListrError(err: Error & { name?: unknown, errors?: unknown }): err is ListrError {
return err.name === "ListrError" && Array.isArray(err.errors) && err.errors.length > 0;
} |
1a4493a
to
ff30197
Compare
9ea19ea
to
7673256
Compare
@jlmessenger Hey, sorry for the late reply 😓 yes, this is exactly what we should do! |
It will be very nice to have this fix! Validation is almost unusable in a context of monorepo right now. The error output is swallowed both by lerna and yarn2 workspaces. Will try to test it locally and will let you know if it'll help with lerna (today or tomorrow). |
@jlmessenger @n1ru4l Just want to let you know that the PR patch is astonishing, amazing, mesmerizing, incredible, brilliant and completely perfect. And it solved our issue with lerna 👍 |
Will this PR be merged? Would help our team a lot! |
Sorry for late response. Could you add a changeset with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR should be adjusted as discribed in #6921 (comment)
@n1ru4l I did the requested changes, however, I feel like the errors manipulation should be done at the print level ( WDYT? |
e71b915
to
aea1cab
Compare
Description
All syntax errors in referenced
*.graphql
files resulted in the CLI displaying the generic error message:Investigation found that that the error details were captured by
listr
but were not printed to the CLI. This change checks for aggregate errors, and include them in the CLI error output.Related #5064
Type of change
Screenshots/Sandbox (if appropriate/relevant):
Adding links to sandbox or providing screenshots can help us understand more about this PR and take action on it as appropriate
How Has This Been Tested?
Tested by running against valid and invalid .graphql files, to ensure the error details were printed out as follows:
Checklist: