Skip to content

Improve error.message #705

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

Merged
merged 1 commit into from
Jan 20, 2024
Merged

Improve error.message #705

merged 1 commit into from
Jan 20, 2024

Conversation

ehmicky
Copy link
Collaborator

@ehmicky ehmicky commented Jan 20, 2024

This PR slightly improves how error.message is built. It also improves the related tests.

@@ -55,8 +64,8 @@ export const makeError = ({
const isError = Object.prototype.toString.call(error) === '[object Error]';
const shortMessage = isError ? `${execaMessage}\n${error.message}` : execaMessage;
const message = [shortMessage, stdio[2], stdio[1], ...stdio.slice(3)]
.map(messagePart => stripFinalNewline(serializeMessagePart(messagePart)))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are joining each part with newlines. If a part ends with a newline, it just results in a single newline, not two.

lib/error.js Outdated
.filter(Boolean)
.map(messagePart => serializeMessagePart(messagePart))
.join('\n');
Copy link
Collaborator Author

@ehmicky ehmicky Jan 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder whether we should separate the error message, stdout and stderr with an empty line or not?

Error: this failed

stdout
...

stderr
...

vs (current behavior)

Error: this failed
stdout
...
stderr
...

The first separates each part in a clearer way. But the second one is more compact. 🤔

Which one do you prefer?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first one

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍

@@ -54,10 +63,11 @@ export const makeError = ({
const execaMessage = `Command ${prefix}: ${command}`;
const isError = Object.prototype.toString.call(error) === '[object Error]';
const shortMessage = isError ? `${execaMessage}\n${error.message}` : execaMessage;
const message = [shortMessage, stdio[2], stdio[1], ...stdio.slice(3)]
const messageStdio = all === undefined ? [stdio[2], stdio[1]] : [all];
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have just added this line too: if all: true is used, the error message should show result.all instead, since it is intertwined, so it is more useful for debugging that splitting stdout and stderr.

@ehmicky ehmicky requested a review from sindresorhus January 20, 2024 18:18
@sindresorhus sindresorhus merged commit 67b476b into main Jan 20, 2024
@sindresorhus sindresorhus deleted the error-message branch January 20, 2024 18:50
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.

None yet

2 participants