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

Add error.signalDescription #378

Merged
merged 7 commits into from
Oct 17, 2019
Merged

Conversation

ehmicky
Copy link
Collaborator

@ehmicky ehmicky commented Oct 14, 2019

At the moment we set error.signal to either undefined or the signal that terminated a process such as "SIGFPE". This PR adds error.signalDescription which is a human-friendly description of that signal such as "Floating point arithmetic error".

This also enhances error messages accordingly such as:

Command was killed with SIGFPE (Floating point arithmetic error)

instead of:

Command was killed with SIGFPE

This uses human-signals, a library I wrote which exports a simple plain object where the key is the signal name and the value the signal description. This works cross-platform.

@sindresorhus
Copy link
Owner

human-signals is great, but it kinda feels like something that should be built-in Node.js. Worth opening an issue on the Node.js issue tracker about that?

@sindresorhus
Copy link
Owner

human-signals brings in https://github.com/zloirock/core-js as a dependency, which I don't think is intentional. If it is, that's not great as it's huge.

index.d.ts Outdated
*/
signal?: string;

/**
A human-friendly description of the signal that was used to terminate the process.
Copy link
Owner

Choose a reason for hiding this comment

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

Can you mention that it's already included in the default Execa error message? So users don't try to be smart and include it themselves and getting it double.

Can you also include a short example of what the description looks like for a signal? (readme too)

Copy link
Owner

Choose a reason for hiding this comment

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

We should also be explicit about that there might be signals with a signalDescription. So users should assume that signalDescription will be defined if signal is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in a92abc0

test/error.js Outdated
@@ -133,6 +133,15 @@ if (process.platform !== 'win32') {
t.is(signal, 'SIGINT');
});

test('error.signalDescription is defined', async t => {
const cp = execa('noop');
Copy link
Owner

Choose a reason for hiding this comment

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

Let's try to use subprocess instead of cp everywhere. Maybe we should add it to https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/prevent-abbreviations.md

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 in 1a5d1cb

I also opened a PR #379 to fix it in all other tests.

index.d.ts Outdated
@@ -254,9 +254,14 @@ declare namespace execa {
killed: boolean;

/**
The signal that was used to terminate the process.
The name of the signal that was used to terminate the process.
Copy link
Owner

Choose a reason for hiding this comment

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

Unrelated to this PR, but I just noticed, when something can be undefined, we should try to describe in what scenarios it's defined vs undefined. This can be a big help for the user in knowing when it will be used.

readme.md Show resolved Hide resolved
@ehmicky
Copy link
Collaborator Author

ehmicky commented Oct 15, 2019

human-signals brings in zloirock/core-js as a dependency, which I don't think is intentional. If it is, that's not great as it's huge.

That's a tough one as I'm using Babel to transpile the library. I've tried to find an option or plugin to inline Babel helpers instead of having Babel inject require('core-js/...') statements but I could not find any. Do you know if that's possible?

@sindresorhus
Copy link
Owner

Why are you even transpiling? Seems like you have a lot of tooling and output bloat/complexity just to be able to use import/export (as the target Node.js version supports most other things). All you really need is https://babeljs.io/docs/en/babel-plugin-transform-modules-commonjs

@ehmicky
Copy link
Collaborator Author

ehmicky commented Oct 15, 2019

Yes it's true the only thing I am using is ES modules there. The thing is I am using this setup with all my projects (which are of different sizes), so I can use other things like Array.flatMap(), Promise.finally(), Promise.allSettled(), async iterators, etc.

However on a small library like this, this does look rather silly.

Actually core-js is only injected by Babel in this project because I use array spread operators. That's supported by Node 8, but unfortunately Array.values() is not, and core-js bundles the two features together at the moment.

I am looking into the best way to remove the core-js dependency in human-signals so that library can be used by Execa. Will come back soon on this PR once I'm done with it.

@ehmicky
Copy link
Collaborator Author

ehmicky commented Oct 16, 2019

Fixed.

I removed the core-js dependency and resolved the points above (with one discussion pending: #378 (comment)).

index.d.ts Outdated Show resolved Hide resolved
readme.md Show resolved Hide resolved
@sindresorhus
Copy link
Owner

I removed the core-js dependency and resolved the points above (with one discussion pending: #378 (comment)).

I also noticed that you're including source maps in the package. Seeing as you don't include the actual source in the package, the source map files are useless, so I would just not produce them. They are also not very valuable as Node.js doesn't use source maps.

@ehmicky
Copy link
Collaborator Author

ehmicky commented Oct 17, 2019

Seeing as you don't include the actual source in the package, the source map files are useless

The sources are included in the source map files in the sourcesContent property: https://unpkg.com/[email protected]/build/src/main.js.map

They are also not very valuable as Node.js doesn't use source maps.

By default they are not used in Node.js for error stack traces. But this can be fixed with either:

It's also used by debuggers. For example if users are debugging some code using --inspect and Chrome DevTools then stepping into a minified dependency, that dependency will show the source code if source maps are defined.

@sindresorhus
Copy link
Owner

The sources are included in the source map files in the sourcesContent property: unpkg.com/[email protected]/build/src/main.js.map

Oh, nice. I didn't know you could embed the source.

@sindresorhus sindresorhus merged commit d8cb08f into master Oct 17, 2019
@sindresorhus sindresorhus deleted the feature/signal-description branch October 17, 2019 15:05
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