hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 46ea6a859a8b8bf5603f94422e2fe26b5de84d72
parent 8404561b565362a1794596799a7925923c0ce769
Author: Drew DeVault <sir@cmpwn.com>
Date:   Mon,  1 Feb 2021 10:40:41 -0500

main.ha: improve error handling

Diffstat:
Mmain.ha | 20++++++++------------
1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/main.ha b/main.ha @@ -6,10 +6,7 @@ export fn main() void = { if (len(os::args) > 1z) { in = match (os::open(os::args[1], io::mode::RDONLY)) { stream: *io::stream => stream, - err: io::error => { - io::errorln(io::errstr(err)); - os::exit(1); - }, + err: io::error => fatal(io::errstr(err)), }; }; defer io::close(in); @@ -19,18 +16,17 @@ export fn main() void = { match (io::read(in, buf[..])) { err: io::error => match (err) { err: io::closed => break, - * => { - io::errorln(io::errstr(err)); - os::exit(1); - }, + * => fatal(io::errstr(err)), }, n: size => match (io::write(os::stdout, buf[..n])) { - err: io::error => { - io::errorln(io::errstr(err)); - os::exit(1); - }, + err: io::error => fatal(io::errstr(err)), * => void, }, }; }; }; + +@noreturn fn fatal(why: str) void = { + io::errorln(why); + os::exit(1); +};