mirror of
https://github.com/oven-sh/bun
synced 2026-02-11 11:29:02 +00:00
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:
@@ -26,7 +26,7 @@ pub const Report = struct {
|
||||
total_lines: u32 = 0,
|
||||
|
||||
pub fn linesCoverageFraction(this: *const Report) f64 {
|
||||
var intersected = this.executable_lines.clone(bun.default_allocator) catch bun.outOfMemory();
|
||||
var intersected = bun.handleOom(this.executable_lines.clone(bun.default_allocator));
|
||||
defer intersected.deinit(bun.default_allocator);
|
||||
intersected.setIntersection(this.lines_which_have_executed);
|
||||
|
||||
@@ -153,7 +153,7 @@ pub const Report = struct {
|
||||
|
||||
try writer.writeAll(comptime prettyFmt("<r><d> | <r>", enable_colors));
|
||||
|
||||
var executable_lines_that_havent_been_executed = report.lines_which_have_executed.clone(bun.default_allocator) catch bun.outOfMemory();
|
||||
var executable_lines_that_havent_been_executed = bun.handleOom(report.lines_which_have_executed.clone(bun.default_allocator));
|
||||
defer executable_lines_that_havent_been_executed.deinit(bun.default_allocator);
|
||||
executable_lines_that_havent_been_executed.toggleAll();
|
||||
|
||||
@@ -237,7 +237,7 @@ pub const Report = struct {
|
||||
|
||||
// ** Track all executable lines **
|
||||
// Executable lines that were not hit should be marked as 0
|
||||
var executable_lines = report.executable_lines.clone(bun.default_allocator) catch bun.outOfMemory();
|
||||
var executable_lines = bun.handleOom(report.executable_lines.clone(bun.default_allocator));
|
||||
defer executable_lines.deinit(bun.default_allocator);
|
||||
var iter = executable_lines.iterator(.{});
|
||||
|
||||
@@ -373,13 +373,13 @@ pub const ByteRangeMapping = struct {
|
||||
pub threadlocal var map: ?*HashMap = null;
|
||||
pub fn generate(str: bun.String, source_contents_str: bun.String, source_id: i32) callconv(.C) void {
|
||||
var _map = map orelse brk: {
|
||||
map = bun.jsc.VirtualMachine.get().allocator.create(HashMap) catch bun.outOfMemory();
|
||||
map = bun.handleOom(bun.jsc.VirtualMachine.get().allocator.create(HashMap));
|
||||
map.?.* = HashMap.init(bun.jsc.VirtualMachine.get().allocator);
|
||||
break :brk map.?;
|
||||
};
|
||||
var slice = str.toUTF8(bun.default_allocator);
|
||||
const hash = bun.hash(slice.slice());
|
||||
var entry = _map.getOrPut(hash) catch bun.outOfMemory();
|
||||
var entry = bun.handleOom(_map.getOrPut(hash));
|
||||
if (entry.found_existing) {
|
||||
entry.value_ptr.deinit();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user