Skip to content

Commit fe0a932

Browse files
committed
Wrap JSON parse errors in readSarifFile with context
1 parent 8e36092 commit fe0a932

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

‎lib/entry-points.js‎

Lines changed: 9 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/sarif/index.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as fs from "fs";
33
import { Logger } from "../logging";
44

55
import * as sarif from "sarif";
6+
import { getErrorMessage } from "../util";
67

78
export type * from "sarif";
89

@@ -48,7 +49,13 @@ export function getToolNames(sarifFile: Partial<sarif.Log>): string[] {
4849
* @returns The resulting JSON value, cast to a SARIF `Log`.
4950
*/
5051
export function readSarifFile(sarifFilePath: string): Partial<sarif.Log> {
51-
return JSON.parse(fs.readFileSync(sarifFilePath, "utf8")) as sarif.Log;
52+
try {
53+
return JSON.parse(fs.readFileSync(sarifFilePath, "utf8")) as sarif.Log;
54+
} catch (err) {
55+
throw new Error(
56+
`Parsing SARIF file at '${sarifFilePath}' failed: ${getErrorMessage(err)}`,
57+
);
58+
}
5259
}
5360

5461
// Takes a list of paths to sarif files and combines them together,

0 commit comments

Comments
 (0)