commit 98bbc15a8c926aaf58c78489c5e4ab4acce1f7ea
parent 784dd6e5475f4df4633d2146b3fee443cadd766d
Author: Sebastian <sebastian@sebsite.pw>
Date: Fri, 8 Sep 2023 00:22:02 -0400
hare::module: improve find error message
For example: when in a non-module directory, `haredoc .`'s error
message now has more context (matching the error message shown by
`hare run .`)
Signed-off-by: Sebastian <sebastian@sebsite.pw>
Diffstat:
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/hare/module/deps.ha b/hare/module/deps.ha
@@ -129,7 +129,6 @@ fn _gather(
case let r: (str, srcset) =>
yield r;
case let e: error =>
- let e = attach(locstr(mod), e);
if (len(stack) == 0) {
return e;
};
diff --git a/hare/module/srcs.ha b/hare/module/srcs.ha
@@ -51,7 +51,14 @@ export fn finish_srcset(srcs: *srcset) void = {
export fn find(ctx: *context, loc: location) ((str, srcset) | error) = {
match (loc) {
case let buf: *path::buffer =>
- return (path::string(buf), path_find(ctx, buf)?);
+ match (path_find(ctx, buf)) {
+ case let s: srcset =>
+ return (path::string(buf), s);
+ case not_found =>
+ return attach(locstr(loc), not_found);
+ case let e: error =>
+ return e;
+ };
case let mod: ast::ident =>
let tok = strings::tokenize(ctx.harepath, ":");
let next: (str | void) = ".";
@@ -74,7 +81,7 @@ export fn find(ctx: *context, loc: location) ((str, srcset) | error) = {
return e;
};
};
- return not_found;
+ return attach(locstr(mod), not_found);
};
};