Skip to content

Commit

Permalink
Merge pull request #112 from forcedotcom/develop
Browse files Browse the repository at this point in the history
merge to develop  master
  • Loading branch information
amphro authored Mar 19, 2019
2 parents 8a6fc47 + 1969592 commit 46815bf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/sfdxError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:');
Expand Down
6 changes: 6 additions & 0 deletions test/unit/sfdxErrorTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 46815bf

Please sign in to comment.