refactor: namespace: leverage errors::ext::swallow where easily applicable
This commit is contained in:
@@ -3,9 +3,10 @@ use fmt;
|
|||||||
use fs;
|
use fs;
|
||||||
use log;
|
use log;
|
||||||
use os::exec;
|
use os::exec;
|
||||||
|
use path;
|
||||||
use rt;
|
use rt;
|
||||||
|
|
||||||
export type error = (fs::error | os::exec::error | rt::errno);
|
export type error = (fs::error | os::exec::error | path::error | rt::errno);
|
||||||
|
|
||||||
// stringify an error. return value is statically allocated, no need to free.
|
// stringify an error. return value is statically allocated, no need to free.
|
||||||
export fn maybe_strerror(what: (void | ...error)) (void | str) = {
|
export fn maybe_strerror(what: (void | ...error)) (void | str) = {
|
||||||
@@ -13,6 +14,7 @@ export fn maybe_strerror(what: (void | ...error)) (void | str) = {
|
|||||||
return match (what) {
|
return match (what) {
|
||||||
case let e: fs::error => yield fs::strerror(e);
|
case let e: fs::error => yield fs::strerror(e);
|
||||||
case let e: os::exec::error => yield os::exec::strerror(e);
|
case let e: os::exec::error => yield os::exec::strerror(e);
|
||||||
|
case let e: path::error => yield path::strerror(e);
|
||||||
case let e: rt::errno =>
|
case let e: rt::errno =>
|
||||||
// N.B.: this panics if the buffer is too small.
|
// N.B.: this panics if the buffer is too small.
|
||||||
yield fmt::bsprintf(errorbuf[..], "{}: {}", rt::errname(e), rt::strerror(e));
|
yield fmt::bsprintf(errorbuf[..], "{}: {}", rt::errname(e), rt::strerror(e));
|
||||||
@@ -27,19 +29,30 @@ export fn strerror(what: error) str = {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export fn check(context: str, what: (void | ...error)) void = {
|
export fn check(context: str, what: (void | ...error), fmt_args: fmt::field...) void = {
|
||||||
|
let context_buf: [4096]u8 = [0...];
|
||||||
match (maybe_strerror(what)) {
|
match (maybe_strerror(what)) {
|
||||||
case let s: str => log::fatalf("{}: {}", context, s);
|
// N.B.: use `fatal(...)` over `fatalf("{}: {}")` so that my treelogger
|
||||||
|
// can extract the context.
|
||||||
|
case let errstr: str => log::fatal(
|
||||||
|
fmt::bsprintf(context_buf[..], context, fmt_args...),
|
||||||
|
":",
|
||||||
|
errstr,
|
||||||
|
);
|
||||||
case void => void;
|
case void => void;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export fn swallow(context: str, what: (void | ...error)) void = {
|
export fn swallow(context: str, what: (void | ...error), fmt_args: fmt::field...) void = {
|
||||||
|
let context_buf: [4096]u8 = [0...];
|
||||||
match (maybe_strerror(what)) {
|
match (maybe_strerror(what)) {
|
||||||
case let s: str =>
|
|
||||||
// N.B.: use `println(...)` over `printfln("{}: {}")` so that my treelogger
|
// N.B.: use `println(...)` over `printfln("{}: {}")` so that my treelogger
|
||||||
// can extract the context.
|
// can extract the context.
|
||||||
log::println(context, ":", s);
|
case let errstr: str => log::println(
|
||||||
|
fmt::bsprintf(context_buf[..], context, fmt_args...),
|
||||||
|
":",
|
||||||
|
errstr,
|
||||||
|
);
|
||||||
case void => void;
|
case void => void;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@@ -202,15 +202,11 @@ fn bind_leaf(old_fs: *fs::fs, new_fs: *fs::fs, user_path: *path::buffer) void =
|
|||||||
yield other;
|
yield other;
|
||||||
};
|
};
|
||||||
|
|
||||||
match (bind_component(old_fs, new_fs, cur_strpath, path::iterrem(&it))) {
|
errors::ext::swallow(
|
||||||
case let e: fs::error =>
|
"[namespace] unable to copy intermediate path {} of {}",
|
||||||
log::printfln("[namespace] unable to copy intermediate path {} of {}: {}", cur_strpath, path_str, fs::strerror(e));
|
bind_component(old_fs, new_fs, cur_strpath, path::iterrem(&it)),
|
||||||
return;
|
cur_strpath, path_str
|
||||||
case let e: path::error =>
|
);
|
||||||
log::printfln("[namespace] unable to copy intermediate path {} of {}: {}", cur_strpath, path_str, path::strerror(e));
|
|
||||||
return;
|
|
||||||
case void => void;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// and now, perform the actual bind mount:
|
// and now, perform the actual bind mount:
|
||||||
|
Reference in New Issue
Block a user