mirror of
https://github.com/zigzap/zap.git
synced 2025-10-20 23:24:09 +00:00
Merge pull request #92 from leroycep/error-return-trace
fix: use error return trace in senderror
This commit is contained in:
commit
789e6b02b8
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 {
|
fn MY_REQUEST_HANDLER(r: zap.Request) void {
|
||||||
MAKE_MEGA_ERROR() catch |err| {
|
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.
|
/// 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
|
// TODO: query accept headers
|
||||||
if (self._internal_sendError(err, errorcode_num)) {
|
if (self._internal_sendError(err, err_trace, errorcode_num)) {
|
||||||
return;
|
return;
|
||||||
} else |_| {
|
} else |_| {
|
||||||
self.sendBody(@errorName(err)) catch return;
|
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.
|
/// 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: query accept headers
|
||||||
// TODO: let's hope 20k is enough. Maybe just really allocate here
|
// TODO: let's hope 20k is enough. Maybe just really allocate here
|
||||||
self.h.*.status = errorcode_num;
|
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();
|
var writer = string.writer();
|
||||||
try writer.print("ERROR: {any}\n\n", .{err});
|
try writer.print("ERROR: {any}\n\n", .{err});
|
||||||
|
|
||||||
|
if (err_trace) |trace| {
|
||||||
const debugInfo = try std.debug.getSelfDebugInfo();
|
const debugInfo = try std.debug.getSelfDebugInfo();
|
||||||
const ttyConfig: std.io.tty.Config = .no_color;
|
const ttyConfig: std.io.tty.Config = .no_color;
|
||||||
try std.debug.writeCurrentStackTrace(writer, debugInfo, ttyConfig, null);
|
try std.debug.writeStackTrace(trace, writer, fba.allocator(), debugInfo, ttyConfig);
|
||||||
|
}
|
||||||
|
|
||||||
try self.sendBody(string.items);
|
try self.sendBody(string.items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue