diff --git a/src/sfdxError.ts b/src/sfdxError.ts index 3e83258cc7..dd29e31ec5 100644 --- a/src/sfdxError.ts +++ b/src/sfdxError.ts @@ -199,7 +199,10 @@ export class SfdxError extends NamedError { * Convert an Error to an SfdxError. * @param err The error to convert. */ - public static wrap(err: Error): SfdxError { + public static wrap(err: Error | string): SfdxError { + if (isString(err)) { + return new SfdxError(err); + } const sfdxError = new SfdxError(err.message, err.name); if (sfdxError.stack) { sfdxError.stack = sfdxError.stack.replace(`${err.name}: ${err.message}`, 'Outer stack:'); diff --git a/test/unit/sfdxErrorTest.ts b/test/unit/sfdxErrorTest.ts index cd5be7e6e7..52c5dac85c 100644 --- a/test/unit/sfdxErrorTest.ts +++ b/test/unit/sfdxErrorTest.ts @@ -115,6 +115,12 @@ describe('SfdxError', () => { expect(mySfdxError).to.be.an.instanceOf(SfdxError); expect(mySfdxError.code).to.equal(myErrorCode); }); + + it('should return a new error with just a string', () => { + const mySfdxError = SfdxError.wrap('test'); + expect(mySfdxError).to.be.an.instanceOf(SfdxError); + expect(mySfdxError.message).to.equal('test'); + }); }); describe('toObject', () => {