Skip to content

Commit

Permalink
fix(npm): do not assume error code is a string (#120)
Browse files Browse the repository at this point in the history
Fixes #119
  • Loading branch information
mcous authored Jul 11, 2023
1 parent c6846a9 commit 730683d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
9 changes: 7 additions & 2 deletions dist/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions dist/main.js.map

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions src/npm/call-npm-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,15 @@ export async function callNpmCli<CommandT extends Command>(
if (exitCode === 0) {
successData = parseJson<SuccessData<CommandT>>(stdout);
} else {
const errorPayload = parseJson<{ error?: { code?: string | null } }>(
const errorPayload = parseJson<{ error?: { code?: unknown } }>(
stdout,
stderr
);

errorCode = errorPayload?.error?.code?.toUpperCase();
if (errorPayload?.error?.code) {
errorCode = String(errorPayload.error.code).toUpperCase();
}

error = new errors.NpmCallError(command, exitCode, stderr);
}

Expand Down Expand Up @@ -109,6 +112,9 @@ async function execNpm(
npm.stdout.on("data", (data) => (stdout += data));
npm.stderr.on("data", (data) => (stderr += data));
npm.on("close", (code) => {
logger?.debug?.(`Received stdout: ${stdout}`);
logger?.debug?.(`Received stderr: ${stderr}`);

resolve({
stdout: stdout.trim(),
stderr: stderr.trim(),
Expand Down

0 comments on commit 730683d

Please sign in to comment.