hare

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

commit b0251a59f1a0f77c9f54f8e94dd9f23cde589213
parent 0f1e5fb4586aa29d9b8d37d06614a9ac72a65521
Author: Scott Little <jupiter@m.rdis.dev>
Date:   Tue, 26 Apr 2022 14:13:32 -0500

Display an error when lookup's mkdirs() fails

When lookup (and, by extension, dirs::config and dirs::cache) cannot
create the computed directory, program execution aborts with an
unhelpful error message, "Assertion failed". This changes that error
message to display the actual error if os::mkdirs() failed.

Signed-off-by: Scott Little <jupiter@m.rdis.dev>
Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Mdirs/xdg.ha | 9++++++++-
Mscripts/gen-stdlib | 2+-
Mstdlib.mk | 4++--
3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/dirs/xdg.ha b/dirs/xdg.ha @@ -2,6 +2,7 @@ // (c) 2021-2022 Drew DeVault <sir@cmpwn.com> // (c) 2021 Eyal Sawady <ecs@d2evs.net> // (c) 2022 Sebastian <sebastian@sebsite.pw> +use fmt; use fs; use os; use path; @@ -27,7 +28,13 @@ fn lookup(prog: str, var: str, default: str) str = { const home = os::getenv("HOME") as str; const path = path::set(&buf, home, default, prog)!; - os::mkdirs(path)!; + match (os::mkdirs(path)) { + case void => + yield; + case let err: fs::error => + fmt::fatal("Error creating {}: {}", + path, fs::strerror(err)); + }; return path; }; diff --git a/scripts/gen-stdlib b/scripts/gen-stdlib @@ -474,7 +474,7 @@ crypto_ed25519() { dirs() { gen_srcs dirs \ xdg.ha - gen_ssa dirs fs io os path + gen_ssa dirs fs io os path fmt } encoding_base64() { diff --git a/stdlib.mk b/stdlib.mk @@ -993,7 +993,7 @@ $(HARECACHE)/datetime/datetime-freebsd.ssa: $(stdlib_datetime_freebsd_srcs) $(st stdlib_dirs_any_srcs = \ $(STDLIB)/dirs/xdg.ha -$(HARECACHE)/dirs/dirs-any.ssa: $(stdlib_dirs_any_srcs) $(stdlib_rt) $(stdlib_fs_$(PLATFORM)) $(stdlib_io_$(PLATFORM)) $(stdlib_os_$(PLATFORM)) $(stdlib_path_$(PLATFORM)) +$(HARECACHE)/dirs/dirs-any.ssa: $(stdlib_dirs_any_srcs) $(stdlib_rt) $(stdlib_fs_$(PLATFORM)) $(stdlib_io_$(PLATFORM)) $(stdlib_os_$(PLATFORM)) $(stdlib_path_$(PLATFORM)) $(stdlib_fmt_$(PLATFORM)) @printf 'HAREC \t$@\n' @mkdir -p $(HARECACHE)/dirs @HARECACHE=$(HARECACHE) $(HAREC) $(HAREFLAGS) -o $@ -Ndirs \ @@ -3040,7 +3040,7 @@ $(TESTCACHE)/datetime/datetime-freebsd.ssa: $(testlib_datetime_freebsd_srcs) $(t testlib_dirs_any_srcs = \ $(STDLIB)/dirs/xdg.ha -$(TESTCACHE)/dirs/dirs-any.ssa: $(testlib_dirs_any_srcs) $(testlib_rt) $(testlib_fs_$(PLATFORM)) $(testlib_io_$(PLATFORM)) $(testlib_os_$(PLATFORM)) $(testlib_path_$(PLATFORM)) +$(TESTCACHE)/dirs/dirs-any.ssa: $(testlib_dirs_any_srcs) $(testlib_rt) $(testlib_fs_$(PLATFORM)) $(testlib_io_$(PLATFORM)) $(testlib_os_$(PLATFORM)) $(testlib_path_$(PLATFORM)) $(testlib_fmt_$(PLATFORM)) @printf 'HAREC \t$@\n' @mkdir -p $(TESTCACHE)/dirs @HARECACHE=$(TESTCACHE) $(HAREC) $(TESTHAREFLAGS) -o $@ -Ndirs \