Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 51 additions & 21 deletions lib/entry-points.js

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

15 changes: 11 additions & 4 deletions src/actions-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
getCodeQLDatabasePath,
ConfigurationError,
getEnv,
getErrorMessage,
} from "./util";

/**
Expand Down Expand Up @@ -413,11 +414,17 @@ export const persistInputs = function (env: Env = getEnv()) {
* Restores all inputs to the action from the persisted state.
*/
export const restoreInputs = function () {
const persistedInputs = core.getState(persistedInputsKey);
if (persistedInputs) {
for (const [name, value] of JSON.parse(persistedInputs)) {
process.env[name] = value;
try {
const persistedInputsValue = core.getState(persistedInputsKey);
if (persistedInputsValue) {
const persistedInputs = JSON.parse(persistedInputsValue);

for (const [name, value] of persistedInputs) {
process.env[name] = value;
}
}
} catch (err) {
throw new Error(`Unable to restore inputs: ${getErrorMessage(err)}`);
}
};

Expand Down
8 changes: 7 additions & 1 deletion src/codeql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,13 @@ async function getCodeQLForCmd(
},
},
).exec();
return JSON.parse(extractorPath) as string;
try {
return JSON.parse(extractorPath) as string;
} catch (err) {
throw new Error(
`Failed to parse extractor path for '${language}' from CLI: ${getErrorMessage(err)}\nOutput was: ${extractorPath}`,
);
}
},
async resolveQueriesStartingPacks(queries: string[]): Promise<string[]> {
const codeqlArgs = [
Expand Down
9 changes: 8 additions & 1 deletion src/sarif/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as fs from "fs";

import { Logger } from "../logging";
import { getErrorMessage } from "../util";

import * as sarif from "sarif";

Expand Down Expand Up @@ -48,7 +49,13 @@ export function getToolNames(sarifFile: Partial<sarif.Log>): string[] {
* @returns The resulting JSON value, cast to a SARIF `Log`.
*/
export function readSarifFile(sarifFilePath: string): Partial<sarif.Log> {
return JSON.parse(fs.readFileSync(sarifFilePath, "utf8")) as sarif.Log;
try {
return JSON.parse(fs.readFileSync(sarifFilePath, "utf8")) as sarif.Log;
} catch (err) {
throw new Error(
`Parsing SARIF file at '${sarifFilePath}' failed: ${getErrorMessage(err)}`,
);
}
}

// Takes a list of paths to sarif files and combines them together,
Expand Down
26 changes: 14 additions & 12 deletions src/tracer-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as path from "path";
import { type CodeQL } from "./codeql";
import { type Config } from "./config-utils";
import { Logger } from "./logging";
import { asyncSome, BuildMode } from "./util";
import { asyncSome, BuildMode, getErrorMessage } from "./util";

export type TracerConfig = {
env: { [key: string]: string };
Expand Down Expand Up @@ -79,18 +79,20 @@ export async function endTracingForCluster(
async function getTracerConfigForCluster(
config: Config,
): Promise<TracerConfig> {
const tracingEnvVariables = JSON.parse(
fs.readFileSync(
path.resolve(
config.dbLocation,
"temp/tracingEnvironment/start-tracing.json",
),
"utf8",
),
const filePath = path.resolve(
config.dbLocation,
"temp/tracingEnvironment/start-tracing.json",
);
return {
env: tracingEnvVariables,
};
try {
const tracingEnvVariables = JSON.parse(fs.readFileSync(filePath, "utf8"));
return {
env: tracingEnvVariables,
};
} catch (err) {
throw new Error(
`Failed to parse tracing environment from '${filePath}': ${getErrorMessage(err)}`,
);
}
}

export async function getCombinedTracerConfig(
Expand Down
14 changes: 12 additions & 2 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,13 @@ export function parseMatrixInput(
if (matrixInput === undefined || matrixInput === "null") {
return undefined;
}
return JSON.parse(matrixInput) as { [key: string]: string };
try {
return JSON.parse(matrixInput) as { [key: string]: string };
} catch (err) {
throw new Error(
`Failed to parse matrix input '${matrixInput}': ${getErrorMessage(err)}`,
);
}
}

export function wrapError(error: unknown): Error {
Expand Down Expand Up @@ -1037,7 +1043,11 @@ export enum BuildMode {
}

export function cloneObject<T>(obj: T): T {
return JSON.parse(JSON.stringify(obj)) as T;
try {
return JSON.parse(JSON.stringify(obj)) as T;
} catch (err) {
throw new Error(`Cloning object failed: ${getErrorMessage(err)}`);
}
}

export async function cleanUpPath(file: string, name: string, logger: Logger) {
Expand Down
Loading