Skip to content

Commit

Permalink
fix: @W-5907580@ respect code if it exist
Browse files Browse the repository at this point in the history
  • Loading branch information
amphro committed Mar 8, 2019
1 parent e94c6c9 commit 5263fe2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 36 deletions.
8 changes: 7 additions & 1 deletion 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 } from '@salesforce/ts-types';
import { ensure, isString, JsonMap, Optional, getString, hasString, ensureString } from '@salesforce/ts-types';
import { Messages, Tokens } from './messages';

/**
Expand Down Expand Up @@ -205,6 +205,10 @@ 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 (hasString(err, 'code')) {
sfdxError.code = ensureString(getString(err, 'code'));
}
return sfdxError;
}

Expand All @@ -231,6 +235,8 @@ 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;

/**
* Create an SfdxError.
* @param message The error message.
Expand Down
12 changes: 12 additions & 0 deletions test/unit/sfdxErrorTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,18 @@ describe('SfdxError', () => {
.to.contain('Outer stack:\n')
.and.contain(myError.stack);
});

it('should return a wrapped error with a code', () => {
class CodeError extends Error {
public code?: string;
}
const myErrorCode = 'OhMyError';
const myError = new CodeError('test');
myError.code = myErrorCode;
const mySfdxError = SfdxError.wrap(myError);
expect(mySfdxError).to.be.an.instanceOf(SfdxError);
expect(mySfdxError.code).to.equal(myErrorCode);
});
});

describe('toObject', () => {
Expand Down
38 changes: 3 additions & 35 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1781,7 +1781,7 @@ debug@^4.0.0, debug@^4.1.0:
dependencies:
ms "^2.1.1"

debuglog@*, debuglog@^1.0.1:
debuglog@^1.0.1:
version "1.0.1"
resolved "https://registry.npmjs.org/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492"
integrity sha1-qiT/uaw9+aI1GDfPstJ5NgzXhJI=
Expand Down Expand Up @@ -2944,7 +2944,7 @@ import-lazy@^2.1.0:
resolved "https://registry.npmjs.org/import-lazy/-/import-lazy-2.1.0.tgz#05698e3d45c88e8d7e9d92cb0584e77f096f3e43"
integrity sha1-BWmOPUXIjo1+nZLLBYTnfwlvPkM=

imurmurhash@*, imurmurhash@^0.1.4:
imurmurhash@^0.1.4:
version "0.1.4"
resolved "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea"
integrity sha1-khi5srkoojixPcT7a21XbyMUU+o=
Expand Down Expand Up @@ -3743,11 +3743,6 @@ lodash-cli@^4:
semver "5.3.0"
uglify-js "2.7.5"

lodash._baseindexof@*:
version "3.1.0"
resolved "https://registry.npmjs.org/lodash._baseindexof/-/lodash._baseindexof-3.1.0.tgz#fe52b53a1c6761e42618d654e4a25789ed61822c"
integrity sha1-/lK1OhxnYeQmGNZU5KJXie1hgiw=

lodash._baseuniq@~4.6.0:
version "4.6.0"
resolved "https://registry.npmjs.org/lodash._baseuniq/-/lodash._baseuniq-4.6.0.tgz#0ebb44e456814af7905c6212fa2c9b2d51b841e8"
Expand All @@ -3756,33 +3751,11 @@ lodash._baseuniq@~4.6.0:
lodash._createset "~4.0.0"
lodash._root "~3.0.0"

lodash._bindcallback@*:
version "3.0.1"
resolved "https://registry.npmjs.org/lodash._bindcallback/-/lodash._bindcallback-3.0.1.tgz#e531c27644cf8b57a99e17ed95b35c748789392e"
integrity sha1-5THCdkTPi1epnhftlbNcdIeJOS4=

lodash._cacheindexof@*:
version "3.0.2"
resolved "https://registry.npmjs.org/lodash._cacheindexof/-/lodash._cacheindexof-3.0.2.tgz#3dc69ac82498d2ee5e3ce56091bafd2adc7bde92"
integrity sha1-PcaayCSY0u5ePOVgkbr9Ktx73pI=

lodash._createcache@*:
version "3.1.2"
resolved "https://registry.npmjs.org/lodash._createcache/-/lodash._createcache-3.1.2.tgz#56d6a064017625e79ebca6b8018e17440bdcf093"
integrity sha1-VtagZAF2JeeevKa4AY4XRAvc8JM=
dependencies:
lodash._getnative "^3.0.0"

lodash._createset@~4.0.0:
version "4.0.3"
resolved "https://registry.npmjs.org/lodash._createset/-/lodash._createset-4.0.3.tgz#0f4659fbb09d75194fa9e2b88a6644d363c9fe26"
integrity sha1-D0ZZ+7CddRlPqeK4imZE02PJ/iY=

lodash._getnative@*, lodash._getnative@^3.0.0:
version "3.9.1"
resolved "https://registry.npmjs.org/lodash._getnative/-/lodash._getnative-3.9.1.tgz#570bc7dede46d61cdcde687d65d3eecbaa3aaff5"
integrity sha1-VwvH3t5G1hzc3mh9ZdPuy6o6r/U=

lodash._reinterpolate@~3.0.0:
version "3.0.0"
resolved "https://registry.npmjs.org/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d"
Expand Down Expand Up @@ -3833,11 +3806,6 @@ lodash.map@^4.5.1:
resolved "https://registry.npmjs.org/lodash.map/-/lodash.map-4.6.0.tgz#771ec7839e3473d9c4cde28b19394c3562f4f6d3"
integrity sha1-dx7Hg540c9nEzeKLGTlMNWL09tM=

lodash.restparam@*:
version "3.6.1"
resolved "https://registry.npmjs.org/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805"
integrity sha1-k2pOMJ7zMKdkXtQUWYbIWuWyCAU=

lodash.set@^4.3.2:
version "4.3.2"
resolved "https://registry.npmjs.org/lodash.set/-/lodash.set-4.3.2.tgz#d8757b1da807dde24816b0d6a84bea1a76230b23"
Expand Down Expand Up @@ -5529,7 +5497,7 @@ readable-stream@~1.1.10:
isarray "0.0.1"
string_decoder "~0.10.x"

readdir-scoped-modules@*, readdir-scoped-modules@^1.0.0:
readdir-scoped-modules@^1.0.0:
version "1.0.2"
resolved "https://registry.npmjs.org/readdir-scoped-modules/-/readdir-scoped-modules-1.0.2.tgz#9fafa37d286be5d92cbaebdee030dc9b5f406747"
integrity sha1-n6+jfShr5dksuuve4DDcm19AZ0c=
Expand Down

0 comments on commit 5263fe2

Please sign in to comment.