Skip to content

Commit

Permalink
remove potential error when setting exit code (#640)
Browse files Browse the repository at this point in the history
* remove potential error setting exit code

this commit implements a more reliable way of setting the CLI's exit code in error cases.

Previously, I encountered this error when running the cli:
```console
$ cordova build
TypeError [ERR_INVALID_ARG_TYPE]: The "code" argument must be of type number. Received type string ('ERR_UNHANDLED_ERROR')
    at process.set [as exitCode] (node:internal/bootstrap/node:123:9)
    at /opt/nodejs/lib/node_modules/cordova/bin/cordova:33:22
```

With this version, I get to see the root problem:
```console
$ cordova build
Unhandled error. ('Parsing /home/me/hello/config.xml failed')
```

* Update cordova
  • Loading branch information
Molkars committed Jun 15, 2024
1 parent c06b573 commit b138eee
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bin/cordova
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ cli(process.argv).catch(err => {
const errorOutput = typeof err === 'string' ? err : util.inspect(err);
throw new CordovaError('Promise rejected with non-error: ' + errorOutput);
}
process.exitCode = err.code || 1;
if (typeof err.code !== 'number') {
process.exitCode = 1;
} else {
process.exitCode = err.code;
}

// We cannot emit an error event here, as that would cause another error
console.error(err.message);
Expand Down

0 comments on commit b138eee

Please sign in to comment.