Commit e514454c0e
Changed files (1)
src-self-hosted
src-self-hosted/main.zig
@@ -728,18 +728,21 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {
}
};
+ var fmt_errors = false;
for (flags.positionals.toSliceConst()) |file_path| {
var file = try os.File.openRead(allocator, file_path);
defer file.close();
const source_code = io.readFileAlloc(allocator, file_path) catch |err| {
try stderr.print("unable to open '{}': {}", file_path, err);
+ fmt_errors = true;
continue;
};
defer allocator.free(source_code);
var tree = std.zig.parse(allocator, source_code) catch |err| {
try stderr.print("error parsing file '{}': {}\n", file_path, err);
+ fmt_errors = true;
continue;
};
defer tree.deinit();
@@ -752,6 +755,7 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {
try errmsg.printToFile(&stderr_file, msg, color);
}
if (tree.errors.len != 0) {
+ fmt_errors = true;
continue;
}
@@ -764,6 +768,10 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {
try baf.finish();
}
}
+
+ if (fmt_errors) {
+ os.exit(1);
+ }
}
// cmd:targets /////////////////////////////////////////////////////////////////////////////////////