fix(log): do not log error.Stop messages

This was a regression caused by the new error trace support. Stop errors
indicate an attempt to navigate outside the bounds of the current document
and are not iteresting to log.
This commit is contained in:
CJ van den Berg 2024-07-02 10:11:01 +02:00
parent 9e323fe85e
commit 65f22d8177
3 changed files with 13 additions and 4 deletions

View file

@ -149,9 +149,10 @@ pub const Logger = struct {
}
const msg___ = buf[0..msg__.len];
@memcpy(msg___, msg__);
if (buf.len - msg___.len > trace__.len) {
const msg____ = buf[0 .. msg__.len + trace__.len];
@memcpy(msg____[msg__.len..], trace__);
if (trace__.len > 0 and buf.len - msg___.len > trace__.len + 1) {
const msg____ = buf[0 .. msg__.len + trace__.len + 1];
@memcpy(msg____[msg__.len .. msg__.len + 1], "\n");
@memcpy(msg____[msg__.len + 1 ..], trace__);
msg = msg____;
} else {
msg = msg___;

View file

@ -94,6 +94,11 @@ pub fn process_log(m: tp.message) !void {
if (try m.match(.{ "log", tp.extract(&src), tp.extract(&msg) })) {
try append(buffer, src, msg, .info);
} else if (try m.match(.{ "log", "error", tp.extract(&src), tp.extract(&context), "->", tp.extract(&msg) })) {
const err_stop = "error.Stop";
if (eql(u8, msg, err_stop))
return;
if (msg.len >= err_stop.len + 1 and eql(u8, msg[0..err_stop.len + 1], err_stop ++ "\n"))
return;
try append_error(buffer, src, context, msg);
} else if (try m.match(.{ "log", tp.extract(&src), tp.more })) {
try append_json(buffer, src, m);

View file

@ -89,7 +89,10 @@ fn process_log(self: *Self, m: tp.message) !void {
if (try m.match(.{ "log", tp.extract(&src), tp.extract(&msg) })) {
try self.set(msg, .info);
} else if (try m.match(.{ "log", "error", tp.extract(&src), tp.extract(&context), "->", tp.extract(&msg) })) {
if (std.mem.eql(u8, msg, "error.Stop"))
const err_stop = "error.Stop";
if (std.mem.eql(u8, msg, err_stop))
return;
if (msg.len >= err_stop.len + 1 and std.mem.eql(u8, msg[0..err_stop.len + 1], err_stop ++ "\n"))
return;
try self.set(msg, .err);
} else if (try m.match(.{ "log", tp.extract(&src), tp.more })) {