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
fix: don't log stacktrace if cli succeeds (regression) #182
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I’m not sure why the tests are failing in Node 14. |
tommy-mitchell
force-pushed
the
fix-cli-message
branch
from
March 14, 2023 06:03
630b2e0
to
dafe675
Compare
Turns out throw new Error(formatter(diagnostics, showDiff), {cause: 'tsd found diagnostics'}); |
tommy-mitchell
commented
Mar 14, 2023
tommy-mitchell
commented
Mar 14, 2023
sindresorhus
requested changes
Mar 14, 2023
It now only throws on failure, and otherwise exits with an error code if any const exit = (message: string, {isError = true}: {isError?: boolean} = {}) => {
if (isError) {
console.error(message);
process.exit(1);
} else {
console.log(message);
process.exit(0);
}
};
try {
// ...
if (diagnostics.length > 0) {
const hasErrors = diagnostics.some(diagnostic => diagnostic.severity === 'error');
const formattedDiagnostics = formatter(diagnostics, showDiff);
exit(formattedDiagnostics, {isError: hasErrors});
}
} catch (error: unknown) {
const potentialError = error as Error | undefined;
const errorMessage = potentialError?.stack ?? potentialError?.message ?? 'tsd unexpectedly crashed.';
exit(`Error running tsd:\n${errorMessage}`);
} |
The formatter also needs to report the number of warnings, but I have another PR for that. Edit: #184 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Starting in
v0.26.1
, successful runs of the CLI (i.e. when it doesn't crash) incorrectly report an error and error stack while runningtsd
:This PR restores the old behavior and makes sure that the error message and stack are only displayed when
tsd
crashes.