Skip to content

Commit 6c871f9

Browse files
authored
Work around npm bug with error reporting (#645)
1 parent 387dddc commit 6c871f9

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

source/npm/util.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,18 @@ exports.prereleaseTags = async packageName => {
9595
tags = Object.keys(JSON.parse(stdout))
9696
.filter(tag => tag !== 'latest');
9797
} catch (error) {
98-
if (((JSON.parse(error.stdout) || {}).error || {}).code !== 'E404') {
98+
// HACK: NPM is mixing JSON with plain text errors. Luckily, the error
99+
// always starts with 'npm ERR!' (unless you have a debugger attached)
100+
// so as a solution, until npm/cli#2740 is fixed, we can remove anything
101+
// starting with 'npm ERR!'
102+
/** @type {string} */
103+
const errorMessage = error.stderr;
104+
const errorJSON = errorMessage
105+
.split('\n')
106+
.filter(error => !error.startsWith('npm ERR!'))
107+
.join('\n');
108+
109+
if (((JSON.parse(errorJSON) || {}).error || {}).code !== 'E404') {
99110
throw error;
100111
}
101112
}

0 commit comments

Comments
 (0)