| ... | @@ -728,18 +728,21 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void { | ... | @@ -728,18 +728,21 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void { |
| 728 | } | 728 | } |
| 729 | }; | 729 | }; |
| 730 | | 730 | |
| | 731 | var fmt_errors = false; |
| 731 | for (flags.positionals.toSliceConst()) |file_path| { | 732 | for (flags.positionals.toSliceConst()) |file_path| { |
| 732 | var file = try os.File.openRead(allocator, file_path); | 733 | var file = try os.File.openRead(allocator, file_path); |
| 733 | defer file.close(); | 734 | defer file.close(); |
| 734 | | 735 | |
| 735 | const source_code = io.readFileAlloc(allocator, file_path) catch |err| { | 736 | const source_code = io.readFileAlloc(allocator, file_path) catch |err| { |
| 736 | try stderr.print("unable to open '{}': {}", file_path, err); | 737 | try stderr.print("unable to open '{}': {}", file_path, err); |
| | 738 | fmt_errors = true; |
| 737 | continue; | 739 | continue; |
| 738 | }; | 740 | }; |
| 739 | defer allocator.free(source_code); | 741 | defer allocator.free(source_code); |
| 740 | | 742 | |
| 741 | var tree = std.zig.parse(allocator, source_code) catch |err| { | 743 | var tree = std.zig.parse(allocator, source_code) catch |err| { |
| 742 | try stderr.print("error parsing file '{}': {}\n", file_path, err); | 744 | try stderr.print("error parsing file '{}': {}\n", file_path, err); |
| | 745 | fmt_errors = true; |
| 743 | continue; | 746 | continue; |
| 744 | }; | 747 | }; |
| 745 | defer tree.deinit(); | 748 | defer tree.deinit(); |
| ... | @@ -752,6 +755,7 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void { | ... | @@ -752,6 +755,7 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void { |
| 752 | try errmsg.printToFile(&stderr_file, msg, color); | 755 | try errmsg.printToFile(&stderr_file, msg, color); |
| 753 | } | 756 | } |
| 754 | if (tree.errors.len != 0) { | 757 | if (tree.errors.len != 0) { |
| | 758 | fmt_errors = true; |
| 755 | continue; | 759 | continue; |
| 756 | } | 760 | } |
| 757 | | 761 | |
| ... | @@ -764,6 +768,10 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void { | ... | @@ -764,6 +768,10 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void { |
| 764 | try baf.finish(); | 768 | try baf.finish(); |
| 765 | } | 769 | } |
| 766 | } | 770 | } |
| | 771 | |
| | 772 | if (fmt_errors) { |
| | 773 | os.exit(1); |
| | 774 | } |
| 767 | } | 775 | } |
| 768 | | 776 | |
| 769 | // cmd:targets ///////////////////////////////////////////////////////////////////////////////////// | 777 | // cmd:targets ///////////////////////////////////////////////////////////////////////////////////// |