From 90ae5b6c3a44a57136b028641b18e572683af96f Mon Sep 17 00:00:00 2001 From: Julian Hurst Date: Tue, 17 Sep 2024 11:25:49 +0200 Subject: Handle full disk errors gracefully --- rng.ha | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/rng.ha b/rng.ha index 93405b4..24e5177 100644 --- a/rng.ha +++ b/rng.ha @@ -6,6 +6,7 @@ use os; use strconv; use sort; use sort::cmp; +use io; export fn main() void = { const cmd = getopt::parse(os::args, @@ -58,16 +59,21 @@ export fn main() void = { sort::sort(rngs: []opaque, size(u32), &cmp::u32s); }; - printrngs(rngs, sep); + match (printrngs(rngs, sep)) { + case void => + yield; + case let e: io::error => + fmt::fatal(io::strerror(e)); + }; }; -fn printrngs(rngs: []u32, sep: str) void = { +fn printrngs(rngs: []u32, sep: str) (void | io::error) = { let s = ""; for (const rng .. rngs) { - fmt::printf("{}{}", s, rng)!; + fmt::printf("{}{}", s, rng)?; s = sep; }; - fmt::println()!; + fmt::println()?; }; fn contains(a: []u32, b: u32) bool = { -- cgit v1.2.3