Replace catch bun.outOfMemory() with safer alternatives (#22141)

Replace `catch bun.outOfMemory()`, which can accidentally catch
non-OOM-related errors, with either `bun.handleOom` or a manual `catch
|err| switch (err)`.

(For internal tracking: fixes STAB-1070)

---------

Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
This commit is contained in:
taylor.fish
2025-08-26 12:50:25 -07:00
committed by GitHub
parent 300f486125
commit 437e15bae5
284 changed files with 1835 additions and 1662 deletions

View File

@@ -1517,7 +1517,7 @@ pub fn transpileSourceCode(
const value = brk: {
if (!jsc_vm.origin.isEmpty()) {
var buf = MutableString.init2048(jsc_vm.allocator) catch bun.outOfMemory();
var buf = bun.handleOom(MutableString.init2048(jsc_vm.allocator));
defer buf.deinit();
var writer = buf.writer();
jsc.API.Bun.getPublicPath(specifier, jsc_vm.origin, @TypeOf(&writer), &writer);
@@ -2079,7 +2079,7 @@ fn dumpSourceStringFailiable(vm: *VirtualMachine, specifier: string, written: []
};
if (vm.source_mappings.get(specifier)) |mappings| {
defer mappings.deref();
const map_path = std.mem.concat(bun.default_allocator, u8, &.{ std.fs.path.basename(specifier), ".map" }) catch bun.outOfMemory();
const map_path = bun.handleOom(std.mem.concat(bun.default_allocator, u8, &.{ std.fs.path.basename(specifier), ".map" }));
defer bun.default_allocator.free(map_path);
const file = try parent.createFile(map_path, .{});
defer file.close();
@@ -2319,7 +2319,7 @@ pub const RuntimeTranspilerStore = struct {
}
if (ast_memory_store == null) {
ast_memory_store = bun.default_allocator.create(js_ast.ASTMemoryAllocator) catch bun.outOfMemory();
ast_memory_store = bun.handleOom(bun.default_allocator.create(js_ast.ASTMemoryAllocator));
ast_memory_store.?.* = js_ast.ASTMemoryAllocator{
.allocator = allocator,
.previous = null,
@@ -2340,7 +2340,7 @@ pub const RuntimeTranspilerStore = struct {
var log = logger.Log.init(allocator);
defer {
this.log = logger.Log.init(bun.default_allocator);
log.cloneToWithRecycled(&this.log, true) catch bun.outOfMemory();
bun.handleOom(log.cloneToWithRecycled(&this.log, true));
}
var vm = this.vm;
var transpiler: bun.Transpiler = undefined;