Fix compile errors introduced by typescript 4.4.2

4.4.2 introduces a breaking change that the variable in a catch clause
is now `unknown` type. So, we need to cast the `e`, `err`, or `error`
variables to type `Error`.
This commit is contained in:
Andrew Eisenberg 2021-09-10 13:53:13 -07:00
parent 5b28adb7ed
commit 40568daca8
83 changed files with 601 additions and 576 deletions

View file

@ -288,13 +288,13 @@ export async function validateWorkflow(): Promise<undefined | string> {
try {
workflow = await getWorkflow();
} catch (e) {
return `error: getWorkflow() failed: ${e.toString()}`;
return `error: getWorkflow() failed: ${String(e)}`;
}
let workflowErrors: CodedError[];
try {
workflowErrors = getWorkflowErrors(workflow);
} catch (e) {
return `error: getWorkflowErrors() failed: ${e.toString()}`;
return `error: getWorkflowErrors() failed: ${String(e)}`;
}
if (workflowErrors.length > 0) {
@ -302,7 +302,7 @@ export async function validateWorkflow(): Promise<undefined | string> {
try {
message = formatWorkflowErrors(workflowErrors);
} catch (e) {
return `error: formatWorkflowErrors() failed: ${e.toString()}`;
return `error: formatWorkflowErrors() failed: ${String(e)}`;
}
core.warning(message);
}

View file

@ -132,7 +132,9 @@ async function run() {
util.getRequiredEnvParam("GITHUB_REPOSITORY")
);
await uploadDatabases(repositoryNwo, config, apiDetails, logger);
} catch (error) {
} catch (origError) {
const error =
origError instanceof Error ? origError : new Error(String(origError));
core.setFailed(error.message);
console.log(error);

View file

@ -302,8 +302,10 @@ export async function runQueries(
logger.info(analysisSummary);
printLinesOfCodeSummary(logger, language, await locPromise);
} catch (e) {
logger.info(e);
logger.info(e.stack);
logger.info(String(e));
if (e instanceof Error) {
logger.info(e.stack!);
}
statusReport.analyze_failure_language = language;
throw new CodeQLAnalysisError(
statusReport,

View file

@ -77,14 +77,16 @@ async function run() {
}
} catch (error) {
core.setFailed(
`We were unable to automatically build your code. Please replace the call to the autobuild action with your custom build steps. ${error.message}`
`We were unable to automatically build your code. Please replace the call to the autobuild action with your custom build steps. ${
error instanceof Error ? error.message : String(error)
}`
);
console.log(error);
await sendCompletedStatusReport(
startedAt,
language ? [language] : [],
language,
error
error instanceof Error ? error : new Error(String(error))
);
return;
}

View file

@ -335,7 +335,7 @@ test("convert to semver", (t) => {
);
t.deepEqual(parsedVersion, expectedVersion);
} catch (e) {
t.fail(e.message);
t.fail(e instanceof Error ? e.message : String(e));
}
}
});

View file

@ -453,7 +453,7 @@ export async function setupCodeQL(
cachedCodeQL = await getCodeQLForCmd(codeqlCmd, checkVersion);
return { codeql: cachedCodeQL, toolsVersion: codeqlURLVersion };
} catch (e) {
logger.error(e);
logger.error(e instanceof Error ? e : new Error(String(e)));
throw new Error("Unable to download and extract CodeQL CLI");
}
}

View file

@ -52,7 +52,7 @@ function getTestConfig(tmpDir: string): Config {
interface LoggedMessage {
type: "debug" | "info" | "warning" | "error";
message: string;
message: string | Error;
}
function getRecordingLogger(messages: LoggedMessage[]): Logger {
@ -65,11 +65,11 @@ function getRecordingLogger(messages: LoggedMessage[]): Logger {
messages.push({ type: "info", message });
console.info(message);
},
warning: (message: string) => {
warning: (message: string | Error) => {
messages.push({ type: "warning", message });
console.warn(message);
},
error: (message: string) => {
error: (message: string | Error) => {
messages.push({ type: "error", message });
console.error(message);
},

View file

@ -175,16 +175,18 @@ async function run() {
try {
await installPythonDeps(codeql, logger);
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
logger.warning(
`${err.message} You can call this action with 'setup-python-dependencies: false' to disable this process`
`${message} You can call this action with 'setup-python-dependencies: false' to disable this process`
);
}
}
} catch (e) {
core.setFailed(e.message);
const message = e instanceof Error ? e.message : String(e);
core.setFailed(message);
console.log(e);
await sendStatusReport(
await createStatusReportBase("init", "aborted", startedAt, e.message)
await createStatusReportBase("init", "aborted", startedAt, message)
);
return;
}
@ -227,15 +229,16 @@ async function run() {
core.setOutput("codeql-path", config.codeQLCmd);
} catch (error) {
core.setFailed(error.message);
core.setFailed(String(error));
console.log(error);
await sendStatusReport(
await createStatusReportBase(
"init",
"failure",
startedAt,
error.message,
error.stack
String(error),
error instanceof Error ? error.stack : undefined
)
);
return;

View file

@ -3,8 +3,8 @@ import * as core from "@actions/core";
export interface Logger {
debug: (message: string) => void;
info: (message: string) => void;
warning: (message: string) => void;
error: (message: string) => void;
warning: (message: string | Error) => void;
error: (message: string | Error) => void;
isDebug: () => boolean;

View file

@ -284,7 +284,7 @@ program
}
} catch (e) {
logger.error("Init failed");
logger.error(e);
logger.error(e instanceof Error ? e : new Error(String(e)));
process.exitCode = 1;
}
});
@ -337,7 +337,7 @@ program
}
} catch (e) {
logger.error("Autobuild failed");
logger.error(e);
logger.error(e instanceof Error ? e : new Error(String(e)));
process.exitCode = 1;
}
});
@ -464,7 +464,7 @@ program
);
} catch (e) {
logger.error("Analyze failed");
logger.error(e);
logger.error(e instanceof Error ? e : new Error(String(e)));
process.exitCode = 1;
}
});
@ -542,7 +542,7 @@ program
);
} catch (e) {
logger.error("Upload failed");
logger.error(e);
logger.error(e instanceof Error ? e : new Error(String(e)));
process.exitCode = 1;
}
});

View file

@ -58,7 +58,7 @@ export async function toolrunnerErrorCatcher(
}
).exec();
} catch (e) {
returnState = e;
returnState = e instanceof Error ? e : new Error(String(e));
}
// if there is a zero return code then we do not apply the matchers

View file

@ -220,7 +220,11 @@ export function countResultsInSarif(sarif: string): number {
try {
parsedSarif = JSON.parse(sarif);
} catch (e) {
throw new Error(`Invalid SARIF. JSON syntax error: ${e.message}`);
throw new Error(
`Invalid SARIF. JSON syntax error: ${
e instanceof Error ? e.message : String(e)
}`
);
}
if (!Array.isArray(parsedSarif.runs)) {
throw new Error("Invalid SARIF. Missing 'runs' array.");

View file

@ -64,15 +64,17 @@ async function run() {
);
await sendSuccessStatusReport(startedAt, uploadStats);
} catch (error) {
core.setFailed(error.message);
const message = error instanceof Error ? error.message : String(error);
const stack = error instanceof Error ? error.stack : String(error);
core.setFailed(message);
console.log(error);
await actionsUtil.sendStatusReport(
await actionsUtil.createStatusReportBase(
"upload-sarif",
"failure",
startedAt,
error.message,
error.stack
message,
stack
)
);
return;

View file

@ -30,8 +30,9 @@ export function getExtraOptionsEnvParam(): object {
try {
return JSON.parse(raw);
} catch (e) {
const message = e instanceof Error ? e.message : String(e);
throw new Error(
`${varName} environment variable is set, but does not contain valid JSON: ${e.message}`
`${varName} environment variable is set, but does not contain valid JSON: ${message}`
);
}
}