Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
Add user friendly message for parse errors in CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
FastAlien committed Sep 10, 2020
1 parent f4c4aee commit 2d7f476
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import fs from "fs";
import {ArgumentParser} from "argparse";
import CppFileMerger from "./CppFileMerger";
import {IncludeFileNotFoundError, ParseError} from "./errors";

enum ErrorCode {
InvalidArgument = 1,
Expand Down Expand Up @@ -81,6 +82,11 @@ try {
process.exit(ErrorCode.WriteError);
}
} catch (error) {
console.error(`Error parsing input file: ${error.message}`);
if (error instanceof ParseError) {
const message = error instanceof IncludeFileNotFoundError ? `Include "${error.includeFile}" not found` : error.message;
console.error(`Error parsing file "${error.file}": ${message}`);
} else {
console.error(`Error parsing file: ${error.message}`);
}
process.exit(ErrorCode.ParseError);
}

0 comments on commit 2d7f476

Please sign in to comment.