commit 24c086a
shrub
·
2026-11-17 15:09:25 +0000 UTC
parent 547d116
better module read failiure error
1 files changed,
+5,
-4
M
module.c
M
module.c
+5,
-4
1@@ -1,4 +1,5 @@
2 #include <string.h>
3+#include <errno.h>
4
5 #include "util.h"
6 #include "kav.h"
7@@ -20,7 +21,7 @@ usepath(const char *from, struct token name) {
8 }
9
10 static struct module *
11-load(const char *path) {
12+load(const char *path, const struct location *at) {
13 struct module *m;
14 struct module *s;
15 struct decl *d;
16@@ -38,12 +39,12 @@ load(const char *path) {
17 seen = m;
18 m->path = path;
19 if(!openreadclose(path, &m->src))
20- diesys("unable to read ", path);
21+ errorat(at, "unable to read ", path, ": ", strerror(errno));
22 sa0(&m->src);
23 m->decls = parse(path, m->src.s);
24 for(d = m->decls; d; d = d->next)
25 if(d->kind == DUSE)
26- d->mod = load(usepath(path, d->name));
27+ d->mod = load(usepath(path, d->name), &d->name.loc);
28 m->state = 2;
29 *end = m;
30 end = &m->next;
31@@ -52,6 +53,6 @@ load(const char *path) {
32
33 struct module *
34 loadall(const char *path) {
35- load(path);
36+ load(path, nil);
37 return head;
38 }