Skip to content

Commit

Permalink
Merge pull request #109 from forcedotcom/develop
Browse files Browse the repository at this point in the history
merge develop to master
  • Loading branch information
amphro committed Mar 18, 2019
2 parents 78924ee + d31bf4c commit 09608fd
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 101 deletions.
4 changes: 3 additions & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ _Describe what actually happened instead_.

_Feel free to attach a screenshot_.

**SFDX CLI Version**:
**SFDX CLI Version**(to find the version of the CLI engine run sfdx --version):

**SFDX plugin Version**(to find the version of the CLI plugin run sfdx plugins --core):

**OS and version**:
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@
"debug": "^3.1.0",
"jsen": "0.6.6",
"jsforce": "1.8.5",
"jsonwebtoken": "7.0.0",
"jsonwebtoken": "8.5.0",
"mkdirp": "0.5.1",
"sfdx-faye": "^1.0.9"
},
"devDependencies": {
"@salesforce/dev-scripts": "0.3.12",
"@types/debug": "0.0.30",
"@types/jsen": "0.0.19",
"@types/jsonwebtoken": "7.2.8",
"@types/jsonwebtoken": "8.3.2",
"@types/mkdirp": "0.5.2",
"@types/shelljs": "0.7.8",
"commitizen": "^3.0.5",
Expand Down
20 changes: 19 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, hasString, isString, JsonMap, Optional } from '@salesforce/ts-types';
import { Messages, Tokens } from './messages';

/**
Expand Down Expand Up @@ -205,6 +205,11 @@ export class SfdxError extends NamedError {
sfdxError.stack = sfdxError.stack.replace(`${err.name}: ${err.message}`, 'Outer stack:');
sfdxError.stack = `${err.stack}\n${sfdxError.stack}`;
}

// If the original error has a code, use that instead of name.
if (hasString(err, 'code')) {
sfdxError.code = err.code;
}
return sfdxError;
}

Expand All @@ -231,6 +236,11 @@ 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

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

/**
* Create an SfdxError.
* @param message The error message.
Expand All @@ -245,6 +255,14 @@ export class SfdxError extends NamedError {
this.exitCode = exitCode || 1;
}

public get code() {
return this._code || this.name;
}

public set code(code: string) {
this._code = code;
}

/**
* Sets the name of the command. For convenience `this` object is returned.
* @param commandName The command name.
Expand Down
2 changes: 1 addition & 1 deletion src/util/sfdc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const sfdc = {
* @param value The path as a string.
*/
validatePathDoesNotContainInvalidChars: (value: string): boolean => {
return !/[\[:"\?<>\|\]]+/.test(value);
return !/[\["\?<>\|\]]+/.test(value);
},

/**
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
3 changes: 3 additions & 0 deletions test/unit/util/sfdcTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ describe('util/sfdc', () => {
it('should return false for "/my/path > err.log"', () => {
expect(sfdc.validatePathDoesNotContainInvalidChars('/my/path > err.log')).to.be.false;
});
it('should return true for "c:\\myfile"', () => {
expect(sfdc.validatePathDoesNotContainInvalidChars('c:\\myfile')).to.be.true;
});
});

describe('findUpperCaseKeys', () => {
Expand Down
Loading

0 comments on commit 09608fd

Please sign in to comment.