make ErrorMatcher an object rather than a tuple
This commit is contained in:
parent
1fb7c81099
commit
b3b99014eb
12 changed files with 58 additions and 48 deletions
10
lib/error-matcher.js
generated
10
lib/error-matcher.js
generated
|
|
@ -5,12 +5,12 @@ exports.namedMatchersForTesting = {
|
|||
/*
|
||||
In due course it may be possible to remove the regex, if/when javascript also exits with code 32.
|
||||
*/
|
||||
noSourceCodeFound: [
|
||||
32,
|
||||
new RegExp("No JavaScript or TypeScript code found\\."),
|
||||
"No code found during the build. Please see:\n" +
|
||||
noSourceCodeFound: {
|
||||
exitCode: 32,
|
||||
outputRegex: new RegExp("No JavaScript or TypeScript code found\\."),
|
||||
message: "No code found during the build. Please see:\n" +
|
||||
"https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/troubleshooting-code-scanning#no-code-found-during-the-build"
|
||||
],
|
||||
},
|
||||
};
|
||||
// we collapse the matches into an array for use in execErrorCatcher
|
||||
exports.errorMatchers = Object.values(exports.namedMatchersForTesting);
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"error-matcher.js","sourceRoot":"","sources":["../src/error-matcher.ts"],"names":[],"mappings":";;AAGA,qCAAqC;AACxB,QAAA,uBAAuB,GAAoC;IACtE;;MAEE;IACF,iBAAiB,EAAE;QACjB,EAAE;QACF,IAAI,MAAM,CAAC,2CAA2C,CAAC;QACvD,+CAA+C;YAC/C,yJAAyJ;KAC1J;CACF,CAAC;AAEF,oEAAoE;AACvD,QAAA,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,+BAAuB,CAAC,CAAC"}
|
||||
{"version":3,"file":"error-matcher.js","sourceRoot":"","sources":["../src/error-matcher.ts"],"names":[],"mappings":";;AASA,qCAAqC;AACxB,QAAA,uBAAuB,GAAoC;IACtE;;MAEE;IACF,iBAAiB,EAAE;QACjB,QAAQ,EAAE,EAAE;QACZ,WAAW,EAAE,IAAI,MAAM,CAAC,2CAA2C,CAAC;QACpE,OAAO,EAAE,+CAA+C;YAC/C,yJAAyJ;KACnK;CACF,CAAC;AAEF,oEAAoE;AACvD,QAAA,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,+BAAuB,CAAC,CAAC"}
|
||||
4
lib/error-matcher.test.js
generated
4
lib/error-matcher.test.js
generated
|
|
@ -20,8 +20,8 @@ function testErrorMatcher(matcherName, logSample) {
|
|||
if (!(matcherName in error_matcher_1.namedMatchersForTesting)) {
|
||||
throw new Error(`Unknown matcher ${matcherName}`);
|
||||
}
|
||||
const regex = error_matcher_1.namedMatchersForTesting[matcherName][1];
|
||||
if (regex === null) {
|
||||
const regex = error_matcher_1.namedMatchersForTesting[matcherName].outputRegex;
|
||||
if (regex === undefined) {
|
||||
throw new Error(`Cannot test matcher ${matcherName} with null regex`);
|
||||
}
|
||||
return regex.test(logSample);
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"error-matcher.test.js","sourceRoot":"","sources":["../src/error-matcher.test.ts"],"names":[],"mappings":";;;;;AACA,8CAAuB;AAEvB,mDAA0D;AAE1D;;EAEE;AAEF,aAAI,CAAC,6DAA6D,EAAE,KAAK,EAAC,CAAC,EAAC,EAAE;IAC5E,CAAC,CAAC,MAAM,CAAC,gBAAgB,CAAC,mBAAmB,EAAE;;;;;GAK9C,CAAC,CAAC,CAAC;AACN,CAAC,CAAC,CAAC;AAEH,SAAS,gBAAgB,CAAC,WAAmB,EAAE,SAAiB;IAE9D,IAAI,CAAC,CAAC,WAAW,IAAI,uCAAuB,CAAC,EAAE;QAC7C,MAAM,IAAI,KAAK,CAAC,mBAAmB,WAAW,EAAE,CAAC,CAAC;KACnD;IACD,MAAM,KAAK,GAAG,uCAAuB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IACtD,IAAI,KAAK,KAAK,IAAI,EAAE;QAClB,MAAM,IAAI,KAAK,CAAC,uBAAuB,WAAW,kBAAkB,CAAC,CAAC;KACvE;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AAC/B,CAAC"}
|
||||
{"version":3,"file":"error-matcher.test.js","sourceRoot":"","sources":["../src/error-matcher.test.ts"],"names":[],"mappings":";;;;;AACA,8CAAuB;AAEvB,mDAA0D;AAE1D;;EAEE;AAEF,aAAI,CAAC,6DAA6D,EAAE,KAAK,EAAC,CAAC,EAAC,EAAE;IAC5E,CAAC,CAAC,MAAM,CAAC,gBAAgB,CAAC,mBAAmB,EAAE;;;;;GAK9C,CAAC,CAAC,CAAC;AACN,CAAC,CAAC,CAAC;AAEH,SAAS,gBAAgB,CAAC,WAAmB,EAAE,SAAiB;IAE9D,IAAI,CAAC,CAAC,WAAW,IAAI,uCAAuB,CAAC,EAAE;QAC7C,MAAM,IAAI,KAAK,CAAC,mBAAmB,WAAW,EAAE,CAAC,CAAC;KACnD;IACD,MAAM,KAAK,GAAG,uCAAuB,CAAC,WAAW,CAAC,CAAC,WAAW,CAAC;IAC/D,IAAI,KAAK,KAAK,SAAS,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,uBAAuB,WAAW,kBAAkB,CAAC,CAAC;KACvE;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AAC/B,CAAC"}
|
||||
10
lib/toolrunner-error-catcher.js
generated
10
lib/toolrunner-error-catcher.js
generated
|
|
@ -20,7 +20,7 @@ const toolrunnner = __importStar(require("@actions/exec/lib/toolrunner"));
|
|||
* @returns Promise<number> exit code
|
||||
*/
|
||||
async function toolrunnerErrorCatcher(commandLine, args, matchers, options) {
|
||||
var _a;
|
||||
var _a, _b, _c;
|
||||
let stdout = '';
|
||||
let stderr = '';
|
||||
let listeners = {
|
||||
|
|
@ -63,15 +63,15 @@ async function toolrunnerErrorCatcher(commandLine, args, matchers, options) {
|
|||
if (returnState === 0)
|
||||
return returnState;
|
||||
if (matchers) {
|
||||
for (const [customCode, regex, message] of matchers) {
|
||||
if (customCode === returnState || regex && (regex.test(stderr) || regex.test(stdout))) {
|
||||
throw new Error(message);
|
||||
for (const matcher of matchers) {
|
||||
if (matcher.exitCode === returnState || ((_a = matcher.outputRegex) === null || _a === void 0 ? void 0 : _a.test(stderr)) || ((_b = matcher.outputRegex) === null || _b === void 0 ? void 0 : _b.test(stdout))) {
|
||||
throw new Error(matcher.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (typeof returnState === 'number') {
|
||||
// only if we were instructed to ignore the return code do we ever return it non-zero
|
||||
if ((_a = options) === null || _a === void 0 ? void 0 : _a.ignoreReturnCode) {
|
||||
if ((_c = options) === null || _c === void 0 ? void 0 : _c.ignoreReturnCode) {
|
||||
return returnState;
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"toolrunner-error-catcher.js","sourceRoot":"","sources":["../src/toolrunner-error-catcher.ts"],"names":[],"mappings":";;;;;;;;;AACA,0EAA4D;AAI5D;;;;;;;;;;GAUG;AACI,KAAK,UAAU,sBAAsB,CAAC,WAAmB,EAAE,IAAe,EACpC,QAAyB,EACzB,OAAwB;;IAEnE,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,MAAM,GAAG,EAAE,CAAC;IAEhB,IAAI,SAAS,GAAG;QACd,MAAM,EAAE,CAAC,IAAY,EAAE,EAAE;;YACvB,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC1B,IAAI,aAAA,OAAO,0CAAE,SAAS,0CAAE,MAAM,MAAK,SAAS,EAAE;gBAC5C,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;aAChC;iBAAM;gBACL,4FAA4F;gBAC5F,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;aAC5B;QAEH,CAAC;QACD,MAAM,EAAE,CAAC,IAAY,EAAE,EAAE;;YACvB,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC1B,IAAI,aAAA,OAAO,0CAAE,SAAS,0CAAE,MAAM,MAAK,SAAS,EAAE;g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,CAAC;QAAE,OAAO,WAAW,CAAC;IAE1C,IAAI,QAAQ,EAAE;QACZ,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;YAC9B,IACE,OAAO,CAAC,QAAQ,KAAK,WAAW,WAChC,OAAO,CAAC,WAAW,0CAAE,IAAI,CAAC,MAAM,EAAC,WACjC,OAAO,CAAC,WAAW,0CAAE,IAAI,CAAC,MAAM,EAAC,EAC/B;gBACF,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;aAClC;SACF;KACF;IAED,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE;QACnC,qFAAqF;QACrF,UAAI,OAAO,0CAAE,gBAAgB,EAAE;YAC7B,OAAO,WAAW,CAAC;SACpB;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,iBAAiB,WAAW,4BAA4B,WAAW,EAAE,CAAC,CAAC;SACxF;KACF;SAAM;QACL,MAAM,WAAW,CAAC;KACnB;AACH,CAAC;AAtED,wDAsEC"}
|
||||
20
lib/toolrunner-error-catcher.test.js
generated
20
lib/toolrunner-error-catcher.test.js
generated
|
|
@ -17,41 +17,41 @@ const toolrunner_error_catcher_1 = require("./toolrunner-error-catcher");
|
|||
testing_utils_1.setupTests(ava_1.default);
|
||||
ava_1.default('matchers are never applied if non-error exit', async (t) => {
|
||||
const testArgs = buildDummyArgs("foo bar\\nblort qux", "foo bar\\nblort qux", '', 0);
|
||||
const matchers = [[123, new RegExp("foo bar"), 'error!!!']];
|
||||
const matchers = [{ exitCode: 123, outputRegex: new RegExp("foo bar"), message: 'error!!!' }];
|
||||
t.deepEqual(await exec.exec('node', testArgs), 0);
|
||||
t.deepEqual(await toolrunner_error_catcher_1.toolrunnerErrorCatcher('node', testArgs, matchers), 0);
|
||||
});
|
||||
ava_1.default('regex matchers are applied to stdout for non-zero exit code', async (t) => {
|
||||
const testArgs = buildDummyArgs("foo bar\\nblort qux", '', '', 1);
|
||||
const matchers = [[123, new RegExp("foo bar"), '🦄']];
|
||||
const matchers = [{ exitCode: 123, outputRegex: new RegExp("foo bar"), message: '🦄' }];
|
||||
await t.throwsAsync(exec.exec('node', testArgs), { instanceOf: Error, message: 'The process \'node\' failed with exit code 1' });
|
||||
await t.throwsAsync(toolrunner_error_catcher_1.toolrunnerErrorCatcher('node', testArgs, matchers), { instanceOf: Error, message: '🦄' });
|
||||
});
|
||||
ava_1.default('regex matchers are applied to stderr for non-zero exit code', async (t) => {
|
||||
const testArgs = buildDummyArgs("non matching string", 'foo bar\\nblort qux', '', 1);
|
||||
const matchers = [[123, new RegExp("foo bar"), '🦄']];
|
||||
const matchers = [{ exitCode: 123, outputRegex: new RegExp("foo bar"), message: '🦄' }];
|
||||
await t.throwsAsync(exec.exec('node', testArgs), { instanceOf: Error, message: 'The process \'node\' failed with exit code 1' });
|
||||
await t.throwsAsync(toolrunner_error_catcher_1.toolrunnerErrorCatcher('node', testArgs, matchers), { instanceOf: Error, message: '🦄' });
|
||||
});
|
||||
ava_1.default('matcher returns correct error message when multiple matchers defined', async (t) => {
|
||||
const testArgs = buildDummyArgs("non matching string", 'foo bar\\nblort qux', '', 1);
|
||||
const matchers = [[456, new RegExp("lorem ipsum"), '😩'],
|
||||
[123, new RegExp("foo bar"), '🦄'],
|
||||
[789, new RegExp("blah blah"), '🤦♂️']];
|
||||
const matchers = [{ exitCode: 456, outputRegex: new RegExp("lorem ipsum"), message: '😩' },
|
||||
{ exitCode: 123, outputRegex: new RegExp("foo bar"), message: '🦄' },
|
||||
{ exitCode: 789, outputRegex: new RegExp("blah blah"), message: '🤦♂️' }];
|
||||
await t.throwsAsync(exec.exec('node', testArgs), { instanceOf: Error, message: 'The process \'node\' failed with exit code 1' });
|
||||
await t.throwsAsync(toolrunner_error_catcher_1.toolrunnerErrorCatcher('node', testArgs, matchers), { instanceOf: Error, message: '🦄' });
|
||||
});
|
||||
ava_1.default('matcher returns first match to regex when multiple matches', async (t) => {
|
||||
const testArgs = buildDummyArgs("non matching string", 'foo bar\\nblort qux', '', 1);
|
||||
const matchers = [[123, new RegExp("foo bar"), '🦄'],
|
||||
[789, new RegExp("blah blah"), '🤦♂️'],
|
||||
[987, new RegExp("foo bar"), '🚫']];
|
||||
const matchers = [{ exitCode: 123, outputRegex: new RegExp("foo bar"), message: '🦄' },
|
||||
{ exitCode: 789, outputRegex: new RegExp("blah blah"), message: '🤦♂️' },
|
||||
{ exitCode: 987, outputRegex: new RegExp("foo bar"), message: '🚫' }];
|
||||
await t.throwsAsync(exec.exec('node', testArgs), { instanceOf: Error, message: 'The process \'node\' failed with exit code 1' });
|
||||
await t.throwsAsync(toolrunner_error_catcher_1.toolrunnerErrorCatcher('node', testArgs, matchers), { instanceOf: Error, message: '🦄' });
|
||||
});
|
||||
ava_1.default('exit code matchers are applied', async (t) => {
|
||||
const testArgs = buildDummyArgs("non matching string", 'foo bar\\nblort qux', '', 123);
|
||||
const matchers = [[123, new RegExp("this will not match"), '🦄']];
|
||||
const matchers = [{ exitCode: 123, outputRegex: new RegExp("this will not match"), message: '🦄' }];
|
||||
await t.throwsAsync(exec.exec('node', testArgs), { instanceOf: Error, message: 'The process \'node\' failed with exit code 123' });
|
||||
await t.throwsAsync(toolrunner_error_catcher_1.toolrunnerErrorCatcher('node', testArgs, matchers), { instanceOf: Error, message: '🦄' });
|
||||
});
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -21,8 +21,8 @@ function testErrorMatcher(matcherName: string, logSample: string): boolean {
|
|||
if (!(matcherName in namedMatchersForTesting)) {
|
||||
throw new Error(`Unknown matcher ${matcherName}`);
|
||||
}
|
||||
const regex = namedMatchersForTesting[matcherName][1];
|
||||
if (regex === null) {
|
||||
const regex = namedMatchersForTesting[matcherName].outputRegex;
|
||||
if (regex === undefined) {
|
||||
throw new Error(`Cannot test matcher ${matcherName} with null regex`);
|
||||
}
|
||||
return regex.test(logSample);
|
||||
|
|
|
|||
|
|
@ -1,17 +1,23 @@
|
|||
|
||||
export type ErrorMatcher = [number|null, RegExp|null, string];
|
||||
// defines properties to match against the result of executed commands,
|
||||
// and a custom error to return when a match is found
|
||||
export interface ErrorMatcher {
|
||||
exitCode?: number; // exit code of the run process
|
||||
outputRegex?: RegExp; // pattern to match against either stdout or stderr
|
||||
message: string; // the error message that will be thrown for a matching process
|
||||
}
|
||||
|
||||
// exported only for testing purposes
|
||||
export const namedMatchersForTesting: { [key: string]: ErrorMatcher } = {
|
||||
/*
|
||||
In due course it may be possible to remove the regex, if/when javascript also exits with code 32.
|
||||
*/
|
||||
noSourceCodeFound: [
|
||||
32,
|
||||
new RegExp("No JavaScript or TypeScript code found\\."),
|
||||
"No code found during the build. Please see:\n" +
|
||||
"https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/troubleshooting-code-scanning#no-code-found-during-the-build"
|
||||
],
|
||||
noSourceCodeFound: {
|
||||
exitCode: 32,
|
||||
outputRegex: new RegExp("No JavaScript or TypeScript code found\\."),
|
||||
message: "No code found during the build. Please see:\n" +
|
||||
"https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/troubleshooting-code-scanning#no-code-found-during-the-build"
|
||||
},
|
||||
};
|
||||
|
||||
// we collapse the matches into an array for use in execErrorCatcher
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ test('matchers are never applied if non-error exit', async t => {
|
|||
|
||||
const testArgs = buildDummyArgs("foo bar\\nblort qux", "foo bar\\nblort qux", '', 0);
|
||||
|
||||
const matchers: ErrorMatcher[] = [[123, new RegExp("foo bar"), 'error!!!']];
|
||||
const matchers: ErrorMatcher[] = [{exitCode: 123, outputRegex: new RegExp("foo bar"), message: 'error!!!' }];
|
||||
|
||||
t.deepEqual(await exec.exec('node', testArgs), 0);
|
||||
|
||||
|
|
@ -23,7 +23,7 @@ test('regex matchers are applied to stdout for non-zero exit code', async t => {
|
|||
|
||||
const testArgs = buildDummyArgs("foo bar\\nblort qux", '', '', 1);
|
||||
|
||||
const matchers: ErrorMatcher[] = [[123, new RegExp("foo bar"), '🦄']];
|
||||
const matchers: ErrorMatcher[] = [{exitCode: 123, outputRegex: new RegExp("foo bar"), message: '🦄' }];
|
||||
|
||||
await t.throwsAsync(exec.exec('node', testArgs), {instanceOf: Error, message: 'The process \'node\' failed with exit code 1'});
|
||||
|
||||
|
|
@ -38,7 +38,7 @@ test('regex matchers are applied to stderr for non-zero exit code', async t => {
|
|||
|
||||
const testArgs = buildDummyArgs("non matching string", 'foo bar\\nblort qux', '', 1);
|
||||
|
||||
const matchers: ErrorMatcher[] = [[123, new RegExp("foo bar"), '🦄']];
|
||||
const matchers: ErrorMatcher[] = [{exitCode: 123, outputRegex: new RegExp("foo bar"), message: '🦄' }];
|
||||
|
||||
await t.throwsAsync(exec.exec('node', testArgs), {instanceOf: Error, message: 'The process \'node\' failed with exit code 1'});
|
||||
|
||||
|
|
@ -53,9 +53,9 @@ test('matcher returns correct error message when multiple matchers defined', asy
|
|||
|
||||
const testArgs = buildDummyArgs("non matching string", 'foo bar\\nblort qux', '', 1);
|
||||
|
||||
const matchers: ErrorMatcher[] = [[456, new RegExp("lorem ipsum"), '😩'],
|
||||
[123, new RegExp("foo bar"), '🦄'],
|
||||
[789, new RegExp("blah blah"), '🤦♂️']];
|
||||
const matchers: ErrorMatcher[] = [{exitCode: 456, outputRegex: new RegExp("lorem ipsum"), message: '😩'},
|
||||
{exitCode: 123, outputRegex: new RegExp("foo bar"), message: '🦄'},
|
||||
{exitCode: 789, outputRegex: new RegExp("blah blah"), message: '🤦♂️'}];
|
||||
|
||||
await t.throwsAsync(exec.exec('node', testArgs), {instanceOf: Error, message: 'The process \'node\' failed with exit code 1'});
|
||||
|
||||
|
|
@ -70,9 +70,9 @@ test('matcher returns first match to regex when multiple matches', async t => {
|
|||
|
||||
const testArgs = buildDummyArgs("non matching string", 'foo bar\\nblort qux', '', 1);
|
||||
|
||||
const matchers: ErrorMatcher[] = [[123, new RegExp("foo bar"), '🦄'],
|
||||
[789, new RegExp("blah blah"), '🤦♂️'],
|
||||
[987, new RegExp("foo bar"), '🚫']];
|
||||
const matchers: ErrorMatcher[] = [{exitCode: 123, outputRegex: new RegExp("foo bar"), message: '🦄'},
|
||||
{exitCode: 789, outputRegex: new RegExp("blah blah"), message: '🤦♂️'},
|
||||
{exitCode: 987, outputRegex: new RegExp("foo bar"), message: '🚫'}];
|
||||
|
||||
await t.throwsAsync(exec.exec('node', testArgs), {instanceOf: Error, message: 'The process \'node\' failed with exit code 1'});
|
||||
|
||||
|
|
@ -87,7 +87,7 @@ test('exit code matchers are applied', async t => {
|
|||
|
||||
const testArgs = buildDummyArgs("non matching string", 'foo bar\\nblort qux', '', 123);
|
||||
|
||||
const matchers: ErrorMatcher[] = [[123, new RegExp("this will not match"), '🦄']];
|
||||
const matchers: ErrorMatcher[] = [{exitCode: 123, outputRegex: new RegExp("this will not match"), message: '🦄' }];
|
||||
|
||||
await t.throwsAsync(exec.exec('node', testArgs), {instanceOf: Error, message: 'The process \'node\' failed with exit code 123'});
|
||||
|
||||
|
|
|
|||
|
|
@ -63,9 +63,13 @@ export async function toolrunnerErrorCatcher(commandLine: string, args?: string[
|
|||
if (returnState === 0) return returnState;
|
||||
|
||||
if (matchers) {
|
||||
for (const [customCode, regex, message] of matchers) {
|
||||
if (customCode === returnState || regex && (regex.test(stderr) || regex.test(stdout)) ) {
|
||||
throw new Error(message);
|
||||
for (const matcher of matchers) {
|
||||
if (
|
||||
matcher.exitCode === returnState ||
|
||||
matcher.outputRegex?.test(stderr) ||
|
||||
matcher.outputRegex?.test(stdout)
|
||||
) {
|
||||
throw new Error(matcher.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue