mirror of
https://github.com/zigzap/zap.git
synced 2025-10-20 15:14:08 +00:00
fix: use error return trace in senderror
This should produce more usable error messages. The error messages before this were pointing at zap runtime functions, instead of at the code that produced the error.
This commit is contained in:
parent
518199fca5
commit
5f4b7957dc
2 changed files with 10 additions and 7 deletions
|
@ -7,7 +7,7 @@ fn MAKE_MEGA_ERROR() !void {
|
|||
|
||||
fn MY_REQUEST_HANDLER(r: zap.Request) void {
|
||||
MAKE_MEGA_ERROR() catch |err| {
|
||||
r.sendError(err, 505);
|
||||
r.sendError(err, if (@errorReturnTrace()) |t| t.* else null, 505);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -319,9 +319,9 @@ pub fn getUserContext(self: *const Self, comptime Context: type) ?*Context {
|
|||
}
|
||||
|
||||
/// Tries to send an error stack trace.
|
||||
pub fn sendError(self: *const Self, err: anyerror, errorcode_num: usize) void {
|
||||
pub fn sendError(self: *const Self, err: anyerror, err_trace: ?std.builtin.StackTrace, errorcode_num: usize) void {
|
||||
// TODO: query accept headers
|
||||
if (self._internal_sendError(err, errorcode_num)) {
|
||||
if (self._internal_sendError(err, err_trace, errorcode_num)) {
|
||||
return;
|
||||
} else |_| {
|
||||
self.sendBody(@errorName(err)) catch return;
|
||||
|
@ -329,7 +329,7 @@ pub fn sendError(self: *const Self, err: anyerror, errorcode_num: usize) void {
|
|||
}
|
||||
|
||||
/// Used internally. Probably does not need to be public.
|
||||
pub fn _internal_sendError(self: *const Self, err: anyerror, errorcode_num: usize) !void {
|
||||
pub fn _internal_sendError(self: *const Self, err: anyerror, err_trace: ?std.builtin.StackTrace, errorcode_num: usize) !void {
|
||||
// TODO: query accept headers
|
||||
// TODO: let's hope 20k is enough. Maybe just really allocate here
|
||||
self.h.*.status = errorcode_num;
|
||||
|
@ -339,9 +339,12 @@ pub fn _internal_sendError(self: *const Self, err: anyerror, errorcode_num: usiz
|
|||
var writer = string.writer();
|
||||
try writer.print("ERROR: {any}\n\n", .{err});
|
||||
|
||||
const debugInfo = try std.debug.getSelfDebugInfo();
|
||||
const ttyConfig: std.io.tty.Config = .no_color;
|
||||
try std.debug.writeCurrentStackTrace(writer, debugInfo, ttyConfig, null);
|
||||
if (err_trace) |trace| {
|
||||
const debugInfo = try std.debug.getSelfDebugInfo();
|
||||
const ttyConfig: std.io.tty.Config = .no_color;
|
||||
try std.debug.writeStackTrace(trace, writer, fba.allocator(), debugInfo, ttyConfig);
|
||||
}
|
||||
|
||||
try self.sendBody(string.items);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue