commit 3566d29c197908319a71f8b9c3148945c792664f
parent d4b4305b9f0a8b38282321ace5b34d6eb8cacf12
Author: Eyal Sawady <ecs@d2evs.net>
Date: Sat, 24 Apr 2021 14:07:44 -0400
Fix further oversights in error handling
Signed-off-by: Eyal Sawady <ecs@d2evs.net>
Diffstat:
23 files changed, 34 insertions(+), 36 deletions(-)
diff --git a/bufio/buffered.ha b/bufio/buffered.ha
@@ -130,7 +130,7 @@ export fn unreadrune(s: *io::stream, rn: rune) void = {
fn buffered_close(s: *io::stream) void = {
assert(s.closer == &buffered_close);
if (s.writer != null) {
- flush(s);
+ flush(s)!;
};
free(s);
};
@@ -138,7 +138,7 @@ fn buffered_close(s: *io::stream) void = {
fn buffered_close_static(s: *io::stream) void = {
assert(s.closer == &buffered_close_static);
if (s.writer != null) {
- flush(s);
+ flush(s)!;
};
free(s);
};
diff --git a/cmd/hare/plan.ha b/cmd/hare/plan.ha
@@ -165,9 +165,9 @@ fn execute(
) (void | exec::error | exec::exit_status!) = {
if (verbose) {
for (let i = 0z; i < len(task.cmd); i += 1) {
- fmt::errorf("{} ", task.cmd[i]);
+ fmt::errorf("{} ", task.cmd[i])!;
};
- fmt::errorln();
+ fmt::errorln()!;
};
let cmd = exec::cmd(task.cmd[0], task.cmd[1..]...)?;
diff --git a/cmd/harec/errors.ha b/cmd/harec/errors.ha
@@ -10,7 +10,7 @@ use strings;
fn printerr(err: parse::error) void = {
match (err) {
err: lex::syntax => printerr_syntax(err),
- err: io::error => fmt::errorln(io::strerror(err)),
+ err: io::error => fmt::errorln(io::strerror(err))!,
};
};
diff --git a/cmd/harec/main.ha b/cmd/harec/main.ha
@@ -59,6 +59,6 @@ export fn main() void = {
};
defer ast::subunit_free(su);
- unparse::subunit(os::stdout, su);
+ unparse::subunit(os::stdout, su)!;
};
};
diff --git a/cmd/haredoc/docstr.ha b/cmd/haredoc/docstr.ha
@@ -122,7 +122,7 @@ fn scanref(par: *parser) (token | void) = {
bufio::scanrune(par.src) as rune; // ]
break;
},
- * => strio::appendrune(buf, rn),
+ * => strio::appendrune(buf, rn)!,
},
* => abort(),
};
diff --git a/crypto/md5/+test.ha b/crypto/md5/+test.ha
@@ -30,7 +30,7 @@ use io;
let hex = strio::dynamic();
defer io::close(hex);
for (let j = 0z; j < SIZE; j += 1) {
- fmt::fprintf(hex, "{:02x}", sum[j]);
+ fmt::fprintf(hex, "{:02x}", sum[j])!;
};
if (strio::string(hex) != vector.1) {
fmt::errorfln("Vector {}: {} != {}",
diff --git a/crypto/sha1/+test.ha b/crypto/sha1/+test.ha
@@ -34,7 +34,7 @@ use io;
let hex = strio::dynamic();
defer io::close(hex);
for (let j = 0z; j < SIZE; j += 1) {
- fmt::fprintf(hex, "{:02x}", sum[j]);
+ fmt::fprintf(hex, "{:02x}", sum[j])!;
};
if (strio::string(hex) != vector.1) {
fmt::errorfln("Vector {}: {} != {}",
diff --git a/crypto/sha256/+test.ha b/crypto/sha256/+test.ha
@@ -31,7 +31,7 @@ use strio;
let hex = strio::dynamic();
defer io::close(hex);
for (let i = 0z; i < SIZE; i += 1) {
- fmt::fprintf(hex, "{:02x}", sum[i]);
+ fmt::fprintf(hex, "{:02x}", sum[i])!;
};
if (strio::string(hex) != vector.1) {
diff --git a/crypto/sha512/+test.ha b/crypto/sha512/+test.ha
@@ -66,7 +66,7 @@ use io;
defer io::close(hex);
for (let j = 0z; j < len(sum); j += 1)
- fmt::fprintf(hex, "{:02x}", sum[j]);
+ fmt::fprintf(hex, "{:02x}", sum[j])!;
if (strio::string(hex) != vector.1) {
fmt::errorfln("Vector {}: {} != {}",
diff --git a/fmt/fmt.ha b/fmt/fmt.ha
@@ -221,7 +221,7 @@ fn format(out: *io::stream, arg: formattable, mod: *modifiers) (size | io::error
};
if (mod.padding == padding::ALIGN_LEFT) {
- format_raw(out, arg, mod);
+ format_raw(out, arg, mod)?;
};
for (z < mod.width: size) {
@@ -229,7 +229,7 @@ fn format(out: *io::stream, arg: formattable, mod: *modifiers) (size | io::error
};
if (mod.padding != padding::ALIGN_LEFT) {
- format_raw(out, arg, mod);
+ format_raw(out, arg, mod)?;
};
return z;
diff --git a/format/xml/parser.ha b/format/xml/parser.ha
@@ -143,7 +143,7 @@ fn scan_attr(par: *parser) (token | error) = {
* => rn,
};
if (rn == quot) break;
- strio::appendrune(par.textbuf, rn);
+ strio::appendrune(par.textbuf, rn)?;
},
};
return (name, strio::string(par.textbuf)): attribute;
@@ -231,7 +231,7 @@ fn scan_content(par: *parser) (text | error) = {
scan_entity(par)?;
},
};
- strio::appendrune(par.textbuf, rn);
+ strio::appendrune(par.textbuf, rn)?;
},
};
return strio::string(par.textbuf);
@@ -289,7 +289,7 @@ fn scan_charref(par: *parser) (rune | error) = {
rn: rune => rn,
};
if (ascii::isdigit(rn)) {
- strio::appendrune(par.entbuf, rn);
+ strio::appendrune(par.entbuf, rn)?;
} else if (rn == ';') {
break;
} else {
diff --git a/fs/mem/+test.ha b/fs/mem/+test.ha
@@ -138,7 +138,7 @@ use strconv;
assert(count == limit);
for (let i = 0z; i < limit; i += 1) {
- fs::remove(memfs, strconv::ztos(i));
+ fs::remove(memfs, strconv::ztos(i))!;
};
let ino = memfs: *inode;
let dir = ino.data as directory;
diff --git a/fs/mem/mem.ha b/fs/mem/mem.ha
@@ -249,9 +249,7 @@ fn remove(fs: *fs::fs, path: str) (void | fs::error) = {
fn close(fs: *fs::fs) void = {
let ino = fs: *inode;
- if (!(ino.data is directory)) {
- return fs::wrongtype;
- };
+ assert(ino.data is directory);
ino.opencount -= 1;
close_rec(ino);
};
diff --git a/fs/mem/stream.ha b/fs/mem/stream.ha
@@ -44,7 +44,7 @@ fn stream_open(
ino.opencount = types::SIZE_MAX;
s.source = bufio::dynamic_from(f, mode);
if (!appnd) {
- bufio::truncate(s.source);
+ bufio::truncate(s.source)?;
};
};
io::seek(s.source, 0, io::whence::SET)?;
@@ -58,7 +58,7 @@ fn read(s: *io::stream, buf: []u8) (size | io::EOF | io::error) = {
fn write(s: *io::stream, buf: const []u8) (size | io::error) = {
let s = s: *stream;
if (s.appnd) {
- io::seek(s.source, 0, io::whence::END);
+ io::seek(s.source, 0, io::whence::END)?;
};
let sz = io::write(s.source, buf)?;
s.inode.data = bufio::buffer(s.source);
diff --git a/getopt/getopts.ha b/getopt/getopts.ha
@@ -219,7 +219,7 @@ export fn printusage(s: *io::stream, name: str, help: []help) void = {
// Prints command help to the provided stream.
export fn printhelp(s: *io::stream, name: str, help: []help) void = {
if (help[0] is cmd_help) {
- fmt::fprintfln(s, "{}: {}\n", name, help[0] as cmd_help: str);
+ fmt::fprintfln(s, "{}: {}\n", name, help[0] as cmd_help: str)!;
};
printusage(s, name, help);
diff --git a/hare/lex/lex.ha b/hare/lex/lex.ha
@@ -185,7 +185,7 @@ fn lex_string(lex: *lexer, loc: location) (token | error) = {
else {
unget(lex, r);
r = lex_rune(lex, loc)?;
- strio::appendrune(buf, r);
+ strio::appendrune(buf, r)?;
},
};
match (nextw(lex)?) {
@@ -244,7 +244,7 @@ fn lex_name(lex: *lexer, loc: location, keyword: bool) (token | error) = {
unget(lex, r);
break;
};
- strio::appendrune(buf, r);
+ strio::appendrune(buf, r)?;
},
};
diff --git a/hare/module/manifest.ha b/hare/module/manifest.ha
@@ -256,7 +256,7 @@ export fn manifest_write(ctx: *context, manifest: *manifest) (void | error) = {
assert(input.stat.mask & want == want);
fmt::fprintfln(fd, "input {} {} {} {}",
hash, input.path, input.stat.inode,
- time::unix(input.stat.mtime));
+ time::unix(input.stat.mtime))?;
};
for (let i = 0z; i < len(manifest.versions); i += 1) {
diff --git a/hare/module/scan.ha b/hare/module/scan.ha
@@ -353,7 +353,7 @@ export fn parsetags(in: str) ([]tag | void) = {
_: void => break,
r: rune => {
if (ascii::isalnum(r) || r == '_') {
- strio::appendrune(buf, r);
+ strio::appendrune(buf, r)!;
} else {
strings::push(&iter, r);
break;
diff --git a/hare/unparse/expr.ha b/hare/unparse/expr.ha
@@ -377,7 +377,7 @@ fn struct_constant(
};
if (sc.autofill) {
newline(out, indent)?;
- fmt::fprint(out, "...");
+ fmt::fprint(out, "...")?;
};
indent -= 1;
newline(out, indent)?;
diff --git a/net/+linux/socket.ha b/net/+linux/socket.ha
@@ -13,7 +13,7 @@ fn connect_fd(
const sockfd = mksockfd(addr)?;
for (let i = 0z; i < len(options); i += 1) {
// The only option is keepalive right now
- setsockopt(sockfd, rt::SO_KEEPALIVE, true);
+ setsockopt(sockfd, rt::SO_KEEPALIVE, true)?;
};
wrap(rt::connect(sockfd, &addr, sockasz(addr)))?;
return sockfd;
@@ -63,9 +63,9 @@ fn listen_fd(
for (let i = 0z; i < len(options); i += 1) {
match (options[i]) {
- _: reuseaddr => setsockopt(sockfd, rt::SO_REUSEADDR, true),
- _: reuseport => setsockopt(sockfd, rt::SO_REUSEPORT, true),
- _: keepalive => setsockopt(sockfd, rt::SO_KEEPALIVE, true),
+ _: reuseaddr => setsockopt(sockfd, rt::SO_REUSEADDR, true)?,
+ _: reuseport => setsockopt(sockfd, rt::SO_REUSEPORT, true)?,
+ _: keepalive => setsockopt(sockfd, rt::SO_KEEPALIVE, true)?,
b: backlog => bk = b,
p: portassignment => portout = p,
};
diff --git a/os/exec/exec+linux.ha b/os/exec/exec+linux.ha
@@ -25,7 +25,7 @@ fn open(path: str) (platform_cmd | errors::opaque) = {
};
};
-fn platform_finish(cmd: *command) void = rt::close(cmd.platform);
+fn platform_finish(cmd: *command) void = rt::close(cmd.platform)!;
fn platform_exec(cmd: *command) errors::opaque = {
// We don't worry about freeing the return values from strings::to_c
diff --git a/rt/+linux/segmalloc.ha b/rt/+linux/segmalloc.ha
@@ -20,7 +20,7 @@ fn segfree(p: *void, s: size) void = {
};
// Marks a segment as writable and drops the execute bit.
-fn segwrite(seg: *void, n: size) void = mprotect(seg, n, PROT_READ | PROT_WRITE);
+fn segwrite(seg: *void, n: size) void = mprotect(seg, n, PROT_READ | PROT_WRITE)!;
// Marks a segment as executable and drops the write bit.
-fn segexec(seg: *void, n: size) void = mprotect(seg, n, PROT_READ | PROT_EXEC);
+fn segexec(seg: *void, n: size) void = mprotect(seg, n, PROT_READ | PROT_EXEC)!;
diff --git a/rt/+test/run.ha b/rt/+test/run.ha
@@ -85,7 +85,7 @@ export fn tests_main() size = {
return nfail;
};
-fn print(msg: str) void = write(1, *(&msg: **void): *const char, len(msg));
+fn print(msg: str) void = write(1, *(&msg: **void): *const char, len(msg))!;
fn dots(n: size) void = {
// XXX: this is slow, I guess