Skip to content

Commit

Permalink
fix: use name by default for code
Browse files Browse the repository at this point in the history
  • Loading branch information
amphro committed Mar 8, 2019
1 parent 5263fe2 commit c5283d3
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/sfdxError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { NamedError } from '@salesforce/kit';
import { ensure, isString, JsonMap, Optional, getString, hasString, ensureString } from '@salesforce/ts-types';
import { ensure, ensureString, getString, hasString, isString, JsonMap, Optional } from '@salesforce/ts-types';
import { Messages, Tokens } from './messages';

/**
Expand Down Expand Up @@ -205,7 +205,8 @@ export class SfdxError extends NamedError {
sfdxError.stack = sfdxError.stack.replace(`${err.name}: ${err.message}`, 'Outer stack:');
sfdxError.stack = `${err.stack}\n${sfdxError.stack}`;
}
// Some errors may have a code, so don't look that information

// If the original error has a code, use that instead of name.
if (hasString(err, 'code')) {
sfdxError.code = ensureString(getString(err, 'code'));
}
Expand Down Expand Up @@ -235,7 +236,10 @@ export class SfdxError extends NamedError {
// Additional data helpful for consumers of this error. E.g., API call result
public data: any; // tslint:disable-line:no-any

public code?: string;
/**
* Some errors support `error.code` instead of `error.name`. This keeps backwards compatability.
*/
public code: string;

/**
* Create an SfdxError.
Expand All @@ -247,6 +251,7 @@ export class SfdxError extends NamedError {
*/
constructor(message: string, name?: string, actions?: string[], exitCode?: number, cause?: Error) {
super(name || 'SfdxError', message, cause);
this.code = this.name;
this.actions = actions;
this.exitCode = exitCode || 1;
}
Expand Down

0 comments on commit c5283d3

Please sign in to comment.