Skip to content

Commit 814d7ff

Browse files
palfreydomoritz
authored andcommitted
Throw errors when problems happen so we get non-zero exit codes (#240)
* Throw errors when problems happen so we get non-zero exit codes * Add test case for output failure * Fix tslint issues
1 parent aa8473d commit 814d7ff

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

test/error.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { assert } from "chai";
2+
import { exec, getDefaultArgs } from "../typescript-json-schema";
3+
import * as path from "path";
4+
5+
describe("error", () => {
6+
it("error-check", () => {
7+
assert.throws(() => {
8+
// This needs a valid path. "dates" chosen basically at random
9+
exec(path.resolve(__dirname, "./programs/dates/"), "MyObject", getDefaultArgs());
10+
}, Error, "No output definition. Probably caused by errors prior to this?");
11+
});
12+
});

typescript-json-schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,14 +1195,14 @@ export function exec(filePattern: string, fullTypeName: string, args = getDefaul
11951195

11961196
const definition = generateSchema(program, fullTypeName, args, onlyIncludeFiles);
11971197
if (definition === null) {
1198-
return;
1198+
throw new Error("No output definition. Probably caused by errors prior to this?");
11991199
}
12001200

12011201
const json = stringify(definition, {space: 4}) + "\n\n";
12021202
if (args.out) {
12031203
require("fs").writeFile(args.out, json, function(err: Error) {
12041204
if (err) {
1205-
console.error("Unable to write output file: " + err.message);
1205+
throw new Error("Unable to write output file: " + err.message);
12061206
}
12071207
});
12081208
} else {

0 commit comments

Comments
 (0)