Passthrough anyerror when using handleOom (#23176)

### What does this PR do?

Previously, handleOom(anyerror!T) would return T and panic for
OutOfMemory for any error. fixes it to return anyerror!T for this case.

### How did you verify your code works?

CI

---------

Co-authored-by: taylor.fish <contact@taylor.fish>
This commit is contained in:
pfg
2025-10-02 14:11:29 -07:00
committed by GitHub
parent d7eebef6f8
commit 2caa5dc8f2
8 changed files with 29 additions and 25 deletions

View File

@@ -210,7 +210,7 @@ pub fn ParseTypescript(
p.popScope();
if (!opts.is_typescript_declare) {
name.ref = bun.handleOom(p.declareSymbol(.ts_namespace, name_loc, name_text));
name.ref = try p.declareSymbol(.ts_namespace, name_loc, name_text);
try p.ref_to_ts_namespace_member.put(p.allocator, name.ref.?, ns_member_data);
}

View File

@@ -1315,10 +1315,10 @@ pub fn VisitStmt(
try p.top_level_enums.append(p.allocator, data.name.ref.?);
}
bun.handleOom(p.recordDeclaredSymbol(data.name.ref.?));
bun.handleOom(p.pushScopeForVisitPass(.entry, stmt.loc));
try p.recordDeclaredSymbol(data.name.ref.?);
try p.pushScopeForVisitPass(.entry, stmt.loc);
defer p.popScope();
bun.handleOom(p.recordDeclaredSymbol(data.arg));
try p.recordDeclaredSymbol(data.arg);
const allocator = p.allocator;
// Scan ahead for any variables inside this namespace. This must be done
@@ -1327,7 +1327,7 @@ pub fn VisitStmt(
// We need to convert the uses into property accesses on the namespace.
for (data.values) |value| {
if (value.ref.isValid()) {
bun.handleOom(p.is_exported_inside_namespace.put(allocator, value.ref, data.arg));
try p.is_exported_inside_namespace.put(allocator, value.ref, data.arg);
}
}
@@ -1336,7 +1336,7 @@ pub fn VisitStmt(
// without initializers are initialized to undefined.
var next_numeric_value: ?f64 = 0.0;
var value_exprs = bun.handleOom(ListManaged(Expr).initCapacity(allocator, data.values.len));
var value_exprs = try ListManaged(Expr).initCapacity(allocator, data.values.len);
var all_values_are_pure = true;

View File

@@ -146,38 +146,38 @@ pub fn writeFormat(this: *Response, comptime Formatter: type, formatter: *Format
try formatter.writeIndent(Writer, writer);
try writer.writeAll(comptime Output.prettyFmt("<r>ok<d>:<r> ", enable_ansi_colors));
try formatter.printAs(.Boolean, Writer, writer, jsc.JSValue.jsBoolean(this.isOK()), .BooleanObject, enable_ansi_colors);
bun.handleOom(formatter.printComma(Writer, writer, enable_ansi_colors));
try formatter.printComma(Writer, writer, enable_ansi_colors);
try writer.writeAll("\n");
try formatter.writeIndent(Writer, writer);
try writer.writeAll(comptime Output.prettyFmt("<r>url<d>:<r> \"", enable_ansi_colors));
try writer.print(comptime Output.prettyFmt("<r><b>{}<r>", enable_ansi_colors), .{this.url});
try writer.writeAll("\"");
bun.handleOom(formatter.printComma(Writer, writer, enable_ansi_colors));
try formatter.printComma(Writer, writer, enable_ansi_colors);
try writer.writeAll("\n");
try formatter.writeIndent(Writer, writer);
try writer.writeAll(comptime Output.prettyFmt("<r>status<d>:<r> ", enable_ansi_colors));
try formatter.printAs(.Double, Writer, writer, jsc.JSValue.jsNumber(this.init.status_code), .NumberObject, enable_ansi_colors);
bun.handleOom(formatter.printComma(Writer, writer, enable_ansi_colors));
try formatter.printComma(Writer, writer, enable_ansi_colors);
try writer.writeAll("\n");
try formatter.writeIndent(Writer, writer);
try writer.writeAll(comptime Output.prettyFmt("<r>statusText<d>:<r> ", enable_ansi_colors));
try writer.print(comptime Output.prettyFmt("<r>\"<b>{}<r>\"", enable_ansi_colors), .{this.init.status_text});
bun.handleOom(formatter.printComma(Writer, writer, enable_ansi_colors));
try formatter.printComma(Writer, writer, enable_ansi_colors);
try writer.writeAll("\n");
try formatter.writeIndent(Writer, writer);
try writer.writeAll(comptime Output.prettyFmt("<r>headers<d>:<r> ", enable_ansi_colors));
try formatter.printAs(.Private, Writer, writer, try this.getHeaders(formatter.globalThis), .DOMWrapper, enable_ansi_colors);
bun.handleOom(formatter.printComma(Writer, writer, enable_ansi_colors));
try formatter.printComma(Writer, writer, enable_ansi_colors);
try writer.writeAll("\n");
try formatter.writeIndent(Writer, writer);
try writer.writeAll(comptime Output.prettyFmt("<r>redirected<d>:<r> ", enable_ansi_colors));
try formatter.printAs(.Boolean, Writer, writer, jsc.JSValue.jsBoolean(this.redirected), .BooleanObject, enable_ansi_colors);
bun.handleOom(formatter.printComma(Writer, writer, enable_ansi_colors));
try formatter.printComma(Writer, writer, enable_ansi_colors);
try writer.writeAll("\n");
formatter.resetLine();

View File

@@ -12,21 +12,21 @@ pub fn writeFormatCredentials(credentials: *S3Credentials, options: bun.S3.Multi
try formatter.writeIndent(Writer, writer);
try writer.writeAll(comptime bun.Output.prettyFmt("<r>endpoint<d>:<r> \"", enable_ansi_colors));
try writer.print(comptime bun.Output.prettyFmt("<r><b>{s}<r>\"", enable_ansi_colors), .{endpoint});
bun.handleOom(formatter.printComma(Writer, writer, enable_ansi_colors));
try formatter.printComma(Writer, writer, enable_ansi_colors);
try writer.writeAll("\n");
const region = if (credentials.region.len > 0) credentials.region else S3Credentials.guessRegion(credentials.endpoint);
try formatter.writeIndent(Writer, writer);
try writer.writeAll(comptime bun.Output.prettyFmt("<r>region<d>:<r> \"", enable_ansi_colors));
try writer.print(comptime bun.Output.prettyFmt("<r><b>{s}<r>\"", enable_ansi_colors), .{region});
bun.handleOom(formatter.printComma(Writer, writer, enable_ansi_colors));
try formatter.printComma(Writer, writer, enable_ansi_colors);
try writer.writeAll("\n");
// PS: We don't want to print the credentials if they are empty just signal that they are there without revealing them
if (credentials.accessKeyId.len > 0) {
try formatter.writeIndent(Writer, writer);
try writer.writeAll(comptime bun.Output.prettyFmt("<r>accessKeyId<d>:<r> \"<r><b>[REDACTED]<r>\"", enable_ansi_colors));
bun.handleOom(formatter.printComma(Writer, writer, enable_ansi_colors));
try formatter.printComma(Writer, writer, enable_ansi_colors);
try writer.writeAll("\n");
}
@@ -34,7 +34,7 @@ pub fn writeFormatCredentials(credentials: *S3Credentials, options: bun.S3.Multi
if (credentials.secretAccessKey.len > 0) {
try formatter.writeIndent(Writer, writer);
try writer.writeAll(comptime bun.Output.prettyFmt("<r>secretAccessKey<d>:<r> \"<r><b>[REDACTED]<r>\"", enable_ansi_colors));
bun.handleOom(formatter.printComma(Writer, writer, enable_ansi_colors));
try formatter.printComma(Writer, writer, enable_ansi_colors);
try writer.writeAll("\n");
}
@@ -42,7 +42,7 @@ pub fn writeFormatCredentials(credentials: *S3Credentials, options: bun.S3.Multi
if (credentials.sessionToken.len > 0) {
try formatter.writeIndent(Writer, writer);
try writer.writeAll(comptime bun.Output.prettyFmt("<r>sessionToken<d>:<r> \"<r><b>[REDACTED]<r>\"", enable_ansi_colors));
bun.handleOom(formatter.printComma(Writer, writer, enable_ansi_colors));
try formatter.printComma(Writer, writer, enable_ansi_colors);
try writer.writeAll("\n");
}
@@ -51,7 +51,7 @@ pub fn writeFormatCredentials(credentials: *S3Credentials, options: bun.S3.Multi
try formatter.writeIndent(Writer, writer);
try writer.writeAll(comptime bun.Output.prettyFmt("<r>acl<d>:<r> ", enable_ansi_colors));
try writer.print(comptime bun.Output.prettyFmt("<r><b>{s}<r>\"", enable_ansi_colors), .{acl_value.toString()});
bun.handleOom(formatter.printComma(Writer, writer, enable_ansi_colors));
try formatter.printComma(Writer, writer, enable_ansi_colors);
try writer.writeAll("\n");
}
@@ -59,14 +59,14 @@ pub fn writeFormatCredentials(credentials: *S3Credentials, options: bun.S3.Multi
try formatter.writeIndent(Writer, writer);
try writer.writeAll(comptime bun.Output.prettyFmt("<r>partSize<d>:<r> ", enable_ansi_colors));
try formatter.printAs(.Double, Writer, writer, jsc.JSValue.jsNumber(options.partSize), .NumberObject, enable_ansi_colors);
bun.handleOom(formatter.printComma(Writer, writer, enable_ansi_colors));
try formatter.printComma(Writer, writer, enable_ansi_colors);
try writer.writeAll("\n");
try formatter.writeIndent(Writer, writer);
try writer.writeAll(comptime bun.Output.prettyFmt("<r>queueSize<d>:<r> ", enable_ansi_colors));
try formatter.printAs(.Double, Writer, writer, jsc.JSValue.jsNumber(options.queueSize), .NumberObject, enable_ansi_colors);
bun.handleOom(formatter.printComma(Writer, writer, enable_ansi_colors));
try formatter.printComma(Writer, writer, enable_ansi_colors);
try writer.writeAll("\n");
try formatter.writeIndent(Writer, writer);

View File

@@ -178,7 +178,9 @@ pub const BundleV2 = struct {
fn ensureClientTranspiler(this: *BundleV2) void {
if (this.client_transpiler == null) {
_ = bun.handleOom(this.initializeClientTranspiler());
_ = this.initializeClientTranspiler() catch |e| {
std.debug.panic("Failed to initialize client transpiler: {s}", .{@errorName(e)});
};
}
}
@@ -233,7 +235,9 @@ pub const BundleV2 = struct {
pub inline fn transpilerForTarget(noalias this: *BundleV2, target: options.Target) *Transpiler {
if (!this.transpiler.options.server_components and this.linker.dev_server == null) {
if (target == .browser and this.transpiler.options.target.isServerSide()) {
return this.client_transpiler orelse bun.handleOom(this.initializeClientTranspiler());
return this.client_transpiler orelse this.initializeClientTranspiler() catch |e| {
std.debug.panic("Failed to initialize client transpiler: {s}", .{@errorName(e)});
};
}
return this.transpiler;

View File

@@ -861,7 +861,7 @@ pub const CommandLineReporter = struct {
}
const output_writer = Output.errorWriter(); // unbuffered. buffered is errorWriterBuffered() / Output.flush()
bun.handleOom(output_writer.writeAll(output_buf.items[initial_length..]));
output_writer.writeAll(output_buf.items[initial_length..]) catch {};
var this: *CommandLineReporter = buntest.reporter orelse return; // command line reporter is missing! uh oh!

View File

@@ -352,7 +352,7 @@ pub fn Printer(comptime Writer: type) type {
pub fn writeFmt(this: *This, comptime fmt: []const u8, args: anytype) PrintErr!void {
// assuming the writer comes from an ArrayList
const start: usize = getWrittenAmt(this.dest);
bun.handleOom(this.dest.print(fmt, args));
this.dest.print(fmt, args) catch return this.addFmtError();
const written = getWrittenAmt(this.dest) - start;
this.col += @intCast(written);
}

View File

@@ -5,7 +5,7 @@ fn isOomOnlyError(comptime ErrorUnionOrSet: type) bool {
.error_set => ErrorUnionOrSet,
else => @compileError("argument must be an error union or error set"),
};
for (@typeInfo(ErrorSet).error_set orelse &.{}) |err| {
for (@typeInfo(ErrorSet).error_set orelse return false) |err| {
if (!std.mem.eql(u8, err.name, "OutOfMemory")) return false;
}
return true;