rayoko/src/errors.zig

25 lines
751 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| {
2020-04-01 19:09:52 +00:00
std.debug.warn("[line {}] Error{} on {}: {}", .{ line, where, ctx, message });
} else {
2020-04-01 19:09:52 +00:00
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);
}
2020-07-23 19:42:49 +00:00
pub fn reportFmt(line: usize, ctx_opt: ?[]const u8, comptime fmt: []const u8, args: anytype) void {
if (ctx_opt) |ctx| {
2020-04-01 19:09:52 +00:00
std.debug.warn("[line {}] Error on {}", .{ line, ctx });
} else {
2020-04-01 19:09:52 +00:00
std.debug.warn("[line {}] Error", .{line});
}
2019-09-18 18:59:11 +00:00
std.debug.warn(fmt, args);
2020-04-01 19:09:52 +00:00
std.debug.warn("\n", .{});
2019-09-18 18:59:11 +00:00
}