ds300 / ds300/patch-package

stderr output (or *any* useful output) missing in some failure cases because of `stdio: "ignore"`

Open
#342 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
11.2k
Forks
325
PR merge metrics
No merged PRs in 30d

Description

I was trying to use patch-package and there was a failure which is probably caused by accidentally using patch-package to try to patch a local fork of a package. But that's not the topic of this issue. What is the topic is that the error message shown on the command line was useless. There was no error message, no stack trace, only a `result` object with on OS numeric error code and no other useful info.

I'd expect to see useful console output for all fatal errors. A numeric error code is not enough to diagnose the problem.

After stepping through patch-package's code in a debugger, I was able to extract the error message by changing the following code: https://github.com/ds300/patch-package/blob/5c2c92bf504885fba4840870a23fc8999c00e572/src/makePatch.ts#L158-L165

When I changed `stdio: 'ignore'` to `stdio: 'pipe'`, now I got console error output from the first `console.error` line (the one that looked at stderr) below:
https://github.com/ds300/patch-package/blob/5c2c92bf504885fba4840870a23fc8999c00e572/src/spawnSafe.ts#L22-L29

I got this console output below, which was helpful in pointing me where I should be looking next to find the root cause, which is probably that I was doing a dumb thing: running patch-package on scripts that I already had patched and `npm pack`-ed in a local fork. This was the useful output:

```
npm WARN using --force Recommended protections disabled.
npm WARN tarball tarball data for react-scripts@file:../../create-react-app/packages/react-scripts/react-scripts-4.0.3.tgz (null) seems to be corrupted. Trying again.
npm WARN tarball tarball data for react-scripts@file:../../create-react-app/packages/react-scripts/react-scripts-4.0.3.tgz (null) seems to be corrupted. Trying again.
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /private/var/folders/5q/3x548yhd5cn1kpm9rq30qvbw0000gn/create-react-app/packages/react-scripts/react-scripts-4.0.3.tgz
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/private/var/folders/5q/3x548yhd5cn1kpm9rq30qvbw0000gn/create-react-app/packages/react-scripts/react-scripts-4.0.3.tgz'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/justingrant/.npm/_logs/2021-08-30T18_40_16_830Z-debug.log
```

Unfortunately, after this console output was printed, before patch-package exited I also got a bunch of non-helpful console output after the useful output above. So simply replacing `'ignore'` with `'pipe'` may not be right fix by itself. Here's the unhelpful output:

```
{
status: 254,
signal: null,
output: [
null,
,

],
pid: 55247,
stdout: ,
stderr: ,
error: null
}
```

Before I patched patch-package (haha!) to enable stderr output, I got the same unhelpful output object shown above, except the `output` property's array elements were all null, and stdout/stderr were not present (or maybe null; can't remember).

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.