commit 46ab97143c1007b0cd7d43b7ed2859e864a40be0
parent 181a2fb16d2809d57841b2d8f649f2b341b5f40b
Author: tongong <tongong@gmx.net>
Date: Fri, 15 Jul 2022 21:46:31 +0200
consistent error format
Diffstat:
4 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/bundle_html.ha b/bundle_html.ha
@@ -77,7 +77,8 @@ fn tacker_html(inputpath: str, ofile: io::handle) void = {
const href = tag_get_attr(tagbuf.buf,
strings::toutf8("href"));
if (href is not_found)
- fixed_fatalf("broken style tag \"{}\".",
+ fixed_fatalf("{}: broken style tag \"{}\".",
+ inputpath,
strings::fromutf8(
tagbuf.buf));
const href = href: tag_split;
diff --git a/bundle_js.ha b/bundle_js.ha
@@ -127,7 +127,7 @@ fn dep_scan(inputpath: str, graph: *dep_graph) void = {
dep_add(inputpath, p, graph);
};
} else {
- fmt::fprintfln(os::stderr, "file \"{}\" could contain skipped require() calls.", inputpath)!;
+ warningf("{}: file could contain skipped require() calls.", inputpath);
break;
};
} else if (m == 1) {
@@ -162,7 +162,8 @@ fn read_require(in: io::handle, path: str) (str | no) = {
io::seek(in, 8, io::whence::CUR)!;
// this weird string contains all characters that are allowed in a js
// source file but not in an identifier
- if (!strings::contains(" !%&()*+,-./:;<=>?[]^{|}~", buf[0]: u32: rune))
+ if (!strings::contains("\t\n\r !%&()*+,-./:;<=>?[]^{|}~", buf[0]: u32:
+ rune))
return no;
io::read(in, buf)!;
@@ -176,6 +177,6 @@ fn read_require(in: io::handle, path: str) (str | no) = {
io::read(in, buf)!;
if (buf[0] == ')') return ret;
};
- fixed_fatalf("{}: broken require() call", path);
+ fixed_fatalf("{}: broken require() call.", path);
return ""; // will not be reached
};
diff --git a/helpers.ha b/helpers.ha
@@ -23,7 +23,7 @@ fn realpath_resolve(path: str) str = {
const p = match (os::realpath(path)) {
case let p: str => yield p;
case let p: fs::error =>
- fixed_fatalf("path \"{}\" does not exist.", path);
+ fixed_fatalf("{}: file does not exist.", path);
yield ""; // unreachable
};
return os::resolve(p);
@@ -35,7 +35,7 @@ fn realpath_resolve(path: str) str = {
fn resolve_path(path: str, from: str) str = {
if (strings::hasprefix(path, "http://") ||
strings::hasprefix(path, "https://")) {
- fixed_fatalf("bundling of external resources is not allowed: \"{}\".",
+ fixed_fatalf("{}: bundling of external resources is not allowed.",
path);
};
// directory path is relativ to base
@@ -50,7 +50,7 @@ fn resolve_path(path: str, from: str) str = {
defer free(r);
const r = strings::dup(realpath_resolve(r));
if (!strings::hasprefix(r, basepath))
- fixed_fatalf("file path \"{}\" violates the base path \"{}\".",
+ fixed_fatalf("{}: file path violates the base path \"{}\".",
r, basepath);
return r;
};
diff --git a/main.ha b/main.ha
@@ -51,14 +51,14 @@ export fn main() void = {
let extstart = lastdotindex(ifile);
if (extstart == -1)
- fixed_fatalf("file \"{}\" has broken filetype.", ifile);
+ fixed_fatalf("{}: broken filetype.", ifile);
let ext = strings::fromutf8(strings::toutf8(ifile)[(extstart + 1)..]);
switch (ext) {
case "html" => tacker_html(ifile, ofile);
case "js" => tacker_js(ifile, ofile, false);
case "css" => tacker_css(ifile, ofile);
- case => fixed_fatalf("unknown filetype: \"{}\".", ifile);
+ case => fixed_fatalf("{}: unknown filetype.", ifile);
};
};
@@ -68,3 +68,7 @@ export fn main() void = {
fn fixed_fatalf(fmt: str, args: fmt::field...) void = {
fmt::fatalf(fmt, args...);
};
+
+fn warningf(fmt: str, args: fmt::field...) void = {
+ fmt::fprintfln(os::stderr, fmt, args...)!;
+};