authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-09-03 15:25:41-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-09-20 18:33:00-07:00
log95439c982033bf56a54f4dd85e6de951b52aeb0d
tree3310fb5184c592db4641db9fff3aeb01a3a21545
parent354c17869a4fb1053d472d6562f4987fbaca143e

std.Progress: avoid problematic catch syntax


1 files changed, 15 insertions(+), 5 deletions(-)

lib/std/Progress.zig+15-5
......@@ -1248,7 +1248,9 @@ fn computeRedraw(serialized_buffer: *Serialized.Buffer) struct { []u8, usize } {
12481248 i += progress_pulsing.len;
12491249 } else {
12501250 const percent = completed_items * 100 / estimated_total;
1251 i += (std.fmt.bufPrint(buf[i..], @"progress_normal {d}", .{percent}) catch &.{}).len;
1251 if (std.fmt.bufPrint(buf[i..], @"progress_normal {d}", .{percent})) |b| {
1252 i += b.len;
1253 } else |_| {}
12521254 }
12531255 },
12541256 .success => {
......@@ -1265,7 +1267,9 @@ fn computeRedraw(serialized_buffer: *Serialized.Buffer) struct { []u8, usize } {
12651267 i += progress_pulsing_error.len;
12661268 } else {
12671269 const percent = completed_items * 100 / estimated_total;
1268 i += (std.fmt.bufPrint(buf[i..], @"progress_error {d}", .{percent}) catch &.{}).len;
1270 if (std.fmt.bufPrint(buf[i..], @"progress_error {d}", .{percent})) |b| {
1271 i += b.len;
1272 } else |_| {}
12691273 }
12701274 },
12711275 }
......@@ -1364,12 +1368,18 @@ fn computeNode(
13641368 if (!is_empty_root) {
13651369 if (name.len != 0 or estimated_total > 0) {
13661370 if (estimated_total > 0) {
1367 i += (std.fmt.bufPrint(buf[i..], "[{d}/{d}] ", .{ completed_items, estimated_total }) catch &.{}).len;
1371 if (std.fmt.bufPrint(buf[i..], "[{d}/{d}] ", .{ completed_items, estimated_total })) |b| {
1372 i += b.len;
1373 } else |_| {}
13681374 } else if (completed_items != 0) {
1369 i += (std.fmt.bufPrint(buf[i..], "[{d}] ", .{completed_items}) catch &.{}).len;
1375 if (std.fmt.bufPrint(buf[i..], "[{d}] ", .{completed_items})) |b| {
1376 i += b.len;
1377 } else |_| {}
13701378 }
13711379 if (name.len != 0) {
1372 i += (std.fmt.bufPrint(buf[i..], "{s}", .{name}) catch &.{}).len;
1380 if (std.fmt.bufPrint(buf[i..], "{s}", .{name})) |b| {
1381 i += b.len;
1382 } else |_| {}
13731383 }
13741384 }
13751385