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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error code is stripped when running execa #10003

Closed
Tallyb opened this issue May 8, 2020 · 3 comments
Closed

Error code is stripped when running execa #10003

Tallyb opened this issue May 8, 2020 · 3 comments

Comments

@Tallyb
Copy link

Tallyb commented May 8, 2020

馃悰 Bug Report

Running execa 4.0.0 with the following code results as follow:

const execa = require('execa');
(async () => {
	// Catching an error
	try {
		let res = (await execa('unknown', ['command']));
	} catch (error) {
		console.log(error);
/*
errno: 'ENOENT',
  code: 'ENOENT',
  syscall: 'spawn unknown',
  path: 'unknown',
  spawnargs: [ 'command' ],
  originalMessage: 'spawn unknown ENOENT',
  shortMessage: 'Command failed with ENOENT: unknown command\nspawn unknown ENOENT',
  command: 'unknown command',
  exitCode: undefined,
  signal: undefined,
  signalDescription: undefined,
  stdout: '',
  stderr: '',
  failed: true,
  timedOut: false,
  isCanceled: false,
  killed: false
  		*/
	}
})();

When running in jest the following code (execa@4 or execa@3):

it ('should have error', async () => {
    try {
        await execa.command('unknown command');
    } catch (e) {
        console.log(`e`);
        expect(e.code).toBeTruthy();
    }
  })
/* {
      "shortMessage": "Command failed with ENOENT: unknown command",
      "command": "unknown command",
      "stdout": "",
      "stderr": "",
      "failed": true,
      "timedOut": false,
      "isCanceled": false,
      "killed": false
    }*/

code and exitCode are missing.

Running the above test with execs@2.0.0 results the following:

{
      "command": "unknown command",
      "exitCode": 2,
      "exitCodeName": "ENOENT",
      "stdout": "",
      "stderr": "",
      "all": "",
      "failed": true,
      "timedOut": false,
      "isCanceled": false,
      "killed": false
    }

I am aware that there are breaking changes between 2 and 3 related to the code, but I am wondering if the exitCode (and code and errno) should remain or not.

It is hard to tell if this is a jest or execa issue.
It is also reported here: sindresorhus/execa#422

@SimenB
Copy link
Member

SimenB commented May 8, 2020

Without checking execa's source code, I assume they use instanceof Error somewhere in their code, and this is caused by #2549

@Tallyb
Copy link
Author

Tallyb commented May 8, 2020

@ehmicky is fixing it on execa: sindresorhus/execa#423

@Tallyb Tallyb closed this as completed May 8, 2020
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants