Skip to content

Commit eefe170

Browse files
rescript format: non-zero exit code when subprocess fails
1 parent ad7fce3 commit eefe170

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

Diff for: scripts/rescript_format.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,25 @@ function main(argv, rescript_exe, bsc_exe) {
9191
process.exit(2);
9292
}
9393
files = output.stdout.split("\n").map((x) => x.trim());
94+
var hasError = false;
9495
for (let arg of files) {
9596
if (isSupportedFile(arg)) {
9697
// console.log(`processing ${arg}`);
9798
child_process.execFile(
9899
bsc_exe,
99100
["-o", arg, "-format", arg],
100-
(error, stdout, stderr) => {
101-
if (error === null) {
102-
// todo
103-
} else {
104-
// todo error handling
101+
(error, _stdout, stderr) => {
102+
if (error !== null) {
105103
console.error(stderr);
104+
hasError = true;
106105
}
107106
}
108107
);
109108
}
110109
}
110+
if (hasError) {
111+
process.exit(2);
112+
}
111113
} else if (use_stdin) {
112114
if (isSupportedStd(use_stdin)) {
113115
var crypto = require("crypto");
@@ -153,6 +155,7 @@ function main(argv, rescript_exe, bsc_exe) {
153155
process.exit(2);
154156
}
155157
}
158+
var hasError = false;
156159
files.forEach((file) => {
157160
var write = isSupportedFile(file);
158161
var flags = write ? ["-o", file, "-format", file] : ["-format", file];
@@ -163,9 +166,13 @@ function main(argv, rescript_exe, bsc_exe) {
163166
}
164167
} else {
165168
console.error(stderr);
169+
hasError = true;
166170
}
167171
});
168172
});
173+
if (hasError) {
174+
process.exit(2);
175+
}
169176
}
170177
} catch (e) {
171178
if (e instanceof arg.ArgError) {

0 commit comments

Comments
 (0)