Skip to content

Commit

Permalink
move error matcher definition into dedicated file
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Fyson committed Sep 7, 2020
1 parent 1f3ce75 commit 7dbaff0
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 12 deletions.
5 changes: 3 additions & 2 deletions lib/codeql.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/codeql.js.map

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions lib/error_matcher.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/error_matcher.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/exec_wrapper.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/exec_wrapper.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/exec_wrapper.test.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/codeql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import uuidV4 from 'uuid/v4';

import * as api from './api-client';
import * as defaults from './defaults.json'; // Referenced from codeql-action-sync-tool!
import { errorMatchers} from './error_matcher';
import { exec_wrapper } from './exec_wrapper';
import { Language } from './languages';
import * as util from './util';
Expand Down Expand Up @@ -390,7 +391,7 @@ function getCodeQLForCmd(cmd: string): CodeQL {
'--',
traceCommand
],
[[0, new RegExp("(No source code was seen during the build\\.|No JavaScript or TypeScript code found\\.)"), 'foo bar']]
errorMatchers
);
},
finalizeDatabase: async function(databasePath: string) {
Expand All @@ -401,7 +402,7 @@ function getCodeQLForCmd(cmd: string): CodeQL {
...getExtraOptionsFromEnv(['database', 'finalize']),
databasePath
],
[[0, new RegExp("(No source code was seen during the build\\.|No JavaScript or TypeScript code found\\.)"), 'foo bar']]);
errorMatchers);
},
resolveQueries: async function(queries: string[], extraSearchPath: string | undefined) {
const codeqlArgs = [
Expand Down
19 changes: 19 additions & 0 deletions src/error_matcher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

export type ErrorMatcher = [number|null, RegExp|null, string];

const namedMatchers: { [key: string]: ErrorMatcher } = {
noSourceCodeFound: [
32,
null,
`No source code was seen during the build. Please see...
https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/troubleshooting-code-scanning#no-code-found-during-the-build`
],
noSourceCodeFoundJavascript: [
null,
new RegExp("No JavaScript or TypeScript code found\\."),
`No source code was seen during the build. Please see...
https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/troubleshooting-code-scanning#no-code-found-during-the-build`
]
};

export const errorMatchers = Object.values(namedMatchers);
3 changes: 2 additions & 1 deletion src/exec_wrapper.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as exec from '@actions/exec';
import test from 'ava';

import { exec_wrapper, ErrorMatcher } from './exec_wrapper';
import { ErrorMatcher } from './error_matcher';
import { exec_wrapper } from './exec_wrapper';
import {setupTests} from './testing-utils';
// import fs from 'fs';

Expand Down
5 changes: 2 additions & 3 deletions src/exec_wrapper.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as exec from '@actions/exec';
import * as im from '@actions/exec/lib/interfaces';


export type ErrorMatcher = [number, RegExp, string];
import {ErrorMatcher} from './error_matcher';

/**
* Wrapper for exec.exec which checks for specific return code and/or regex matches in console output.
Expand Down Expand Up @@ -64,7 +63,7 @@ export async function exec_wrapper(commandLine: string, args?: string[],

if (matchers) {
for (const [customCode, regex, message] of matchers) {
if (customCode === returnState || regex.test(stderr) || regex.test(stdout) ) {
if (customCode === returnState || regex && (regex.test(stderr) || regex.test(stdout)) ) {
throw new Error(message);
}
}
Expand Down

0 comments on commit 7dbaff0

Please sign in to comment.