From e05f33a8b6b8a981ea8dd637ab4dedef9742edde Mon Sep 17 00:00:00 2001 From: Dylan Conway Date: Mon, 9 Sep 2024 18:09:05 -0700 Subject: [PATCH] unnecessary error check --- src/shell/interpreter.zig | 46 ++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/shell/interpreter.zig b/src/shell/interpreter.zig index 8583984910..8834303802 100644 --- a/src/shell/interpreter.zig +++ b/src/shell/interpreter.zig @@ -10513,31 +10513,33 @@ pub const Interpreter = struct { var total: f64 = 0; while (iter.next()) |arg| { - const trimmed = bun.strings.trimLeft(bun.sliceTo(arg, 0), " "); + invalid_interval: { + const trimmed = bun.strings.trimLeft(bun.sliceTo(arg, 0), " "); - if (trimmed.len == 0 or trimmed[0] == '-') { - return this.fail("sleep: invalid time interval\n"); + if (trimmed.len == 0 or trimmed[0] == '-') { + break :invalid_interval; + } + + const seconds = bun.fmt.parseFloat(f64, trimmed) catch { + break :invalid_interval; + }; + + if (std.math.isInf(seconds)) { + // if positive infinity is seen, set total to `-1`. + // continue iterating to catch invalid args + total = -1; + } else if (std.math.isNan(seconds)) { + break :invalid_interval; + } + + if (total != -1) { + total += seconds; + } + + continue; } - const seconds = bun.fmt.parseFloat(f64, trimmed) catch { - return this.fail("sleep: invalid time interval\n"); - }; - - if (std.math.isInf(seconds)) { - // if positive infinity is seen, set total to `-1`. - // continue iterating to catch invalid args - total = -1; - } else if (std.math.isNan(seconds)) { - return this.fail("sleep: invalid time interval\n"); - } - - if (total != -1) { - total += seconds; - } - } - - if (this.state == .err) { - return Maybe(void).success; + return this.fail("sleep: invalid time interval\n"); } if (total != 0) {