Skip to content

Commit 535bab1

Browse files
committed
refactor: better error handling when JSON request fails to parse
Will report the actual JSON string not just the fact that it failed. Signed-off-by: Peter Somogyvari <[email protected]>
1 parent 608f1d1 commit 535bab1

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Diff for: pkg/cmd-api-server/src/main/typescript/cmd/dci-lint-cli.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from "@dci-lint/core-api";
1212

1313
import { launchApiServerApp } from "./dci-lint-server";
14+
import { RuntimeError } from "run-time-error";
1415

1516
const log: Logger = LoggerProvider.getOrCreate({
1617
label: "api",
@@ -55,7 +56,15 @@ export async function launchCliApp(): Promise<void> {
5556
},
5657
async (args: any) => {
5758
log.info(`Parsing request JSON: ${args.request}`);
58-
const req = JSON.parse(args.request) as LintGitRepoRequest;
59+
let req: LintGitRepoRequest;
60+
try {
61+
req = JSON.parse(args.request) as LintGitRepoRequest;
62+
} catch (ex) {
63+
throw new RuntimeError(
64+
`Failed to parse JSON request from CLI: ${args.request}`,
65+
ex
66+
);
67+
}
5968
const res = await main(req);
6069
if (args.pretty) {
6170
// tslint:disable-next-line: no-console

0 commit comments

Comments
 (0)