mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-01-18 02:39:49 +00:00
Fix handling of thrown strings
Change-type: patch Signed-off-by: Scott Lowe <scott@balena.io>
This commit is contained in:
parent
1f74889386
commit
d3586696b4
@ -219,7 +219,12 @@ async function sentryCaptureException(error: Error) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function handleError(error: Error) {
|
||||
export async function handleError(error: Error | string) {
|
||||
// If a module has thrown a string, convert to error
|
||||
if (typeof error === 'string') {
|
||||
error = new Error(error);
|
||||
}
|
||||
|
||||
// Set appropriate exitCode
|
||||
process.exitCode =
|
||||
(error as BalenaError).exitCode === 0
|
||||
|
@ -99,6 +99,18 @@ describe('handleError() function', () => {
|
||||
expect(printExpectedErrorMessage.notCalled);
|
||||
});
|
||||
|
||||
it('should process thrown strings correctly', async () => {
|
||||
const error = 'an thrown string';
|
||||
await ErrorsModule.handleError(error);
|
||||
|
||||
expect(printErrorMessage.calledOnce).to.be.true;
|
||||
expect(printErrorMessage.getCall(0).args[0]).to.equal(error);
|
||||
expect(captureException.calledOnce).to.be.true;
|
||||
expect(processExit.calledOnce).to.be.true;
|
||||
|
||||
expect(printExpectedErrorMessage.notCalled);
|
||||
});
|
||||
|
||||
it('should process unexpected errors correctly (debug)', async () => {
|
||||
sandbox.stub(process, 'env').value({ DEBUG: true });
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user