Commit cf898e242a

Andrew Kelley <andrew@ziglang.org>
2025-01-16 04:43:46
std.Build.Step.CheckObject: better EOF handling
when unexpected end of stream occurs, just add that as a token into the text
1 parent 6053112
Changed files (1)
lib
std
Build
lib/std/Build/Step/CheckObject.zig
@@ -2424,7 +2424,22 @@ const WasmDumper = struct {
         }
 
         var output = std.ArrayList(u8).init(gpa);
-        errdefer output.deinit();
+        defer output.deinit();
+        parseAndDumpInner(step, check, bytes, &fbs, &output) catch |err| switch (err) {
+            error.EndOfStream => try output.appendSlice("\n<UnexpectedEndOfStream>"),
+            else => |e| return e,
+        };
+        return output.toOwnedSlice();
+    }
+
+    fn parseAndDumpInner(
+        step: *Step,
+        check: Check,
+        bytes: []const u8,
+        fbs: *std.io.FixedBufferStream([]const u8),
+        output: *std.ArrayList(u8),
+    ) !void {
+        const reader = fbs.reader();
         const writer = output.writer();
 
         switch (check.kind) {
@@ -2442,8 +2457,6 @@ const WasmDumper = struct {
 
             else => return step.fail("invalid check kind for Wasm file format: {s}", .{@tagName(check.kind)}),
         }
-
-        return output.toOwnedSlice();
     }
 
     fn parseAndDumpSection(