rayoko/src/errors.zig

25 lines
724 B
Zig
Raw Normal View History

2019-09-18 18:59:11 +00:00
const std = @import("std");
pub fn report(line: usize, where: []const u8, ctx_opt: ?[]const u8, message: []const u8) void {
if (ctx_opt) |ctx| {
std.debug.warn("[line {}] Error{} on {}: {}", line, where, ctx, message);
} else {
std.debug.warn("[line {}] Error{}: {}", line, where, message);
}
2019-09-18 18:59:11 +00:00
}
pub fn reportN(line: usize, message: []const u8) void {
report(line, "", message);
}
pub fn reportFmt(line: usize, ctx_opt: ?[]const u8, comptime fmt: []const u8, args: ...) void {
if (ctx_opt) |ctx| {
std.debug.warn("[line {}] Error on {}", line, ctx);
} else {
std.debug.warn("[line {}] Error", line);
}
2019-09-18 18:59:11 +00:00
std.debug.warn(fmt, args);
std.debug.warn("\n");
}