fix erroneous test error
This commit is contained in:
parent
b187fa80eb
commit
5cf0be6f23
|
@ -1,4 +1,5 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
const builtin = @import("builtin");
|
||||||
|
|
||||||
// C interfaces between main and libraries
|
// C interfaces between main and libraries
|
||||||
pub const Header = extern struct {
|
pub const Header = extern struct {
|
||||||
|
@ -129,10 +130,7 @@ pub fn handleRequest(request: *Request, zigRequestHandler: ZigRequestHandler) ?*
|
||||||
.name = request.headers[i].name_ptr[0..request.headers[i].name_len],
|
.name = request.headers[i].name_ptr[0..request.headers[i].name_len],
|
||||||
.value = request.headers[i].value_ptr[0..request.headers[i].value_len],
|
.value = request.headers[i].value_ptr[0..request.headers[i].value_len],
|
||||||
}) catch |e| {
|
}) catch |e| {
|
||||||
log.err("Unexpected error processing request: {any}", .{e});
|
logError("Unexpected error processing request: {any}", .{e}, @errorReturnTrace());
|
||||||
if (@errorReturnTrace()) |trace| {
|
|
||||||
std.debug.dumpStackTrace(trace.*);
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -146,10 +144,7 @@ pub fn handleRequest(request: *Request, zigRequestHandler: ZigRequestHandler) ?*
|
||||||
.target = request.target[0..request.target_len],
|
.target = request.target[0..request.target_len],
|
||||||
.method = request.method[0..request.method_len :0],
|
.method = request.method[0..request.method_len :0],
|
||||||
.headers = request_headers.toOwnedSlice() catch |e| {
|
.headers = request_headers.toOwnedSlice() catch |e| {
|
||||||
log.err("Unexpected error processing request: {any}", .{e});
|
logError("Unexpected error processing request: {any}", .{e}, @errorReturnTrace());
|
||||||
if (@errorReturnTrace()) |trace| {
|
|
||||||
std.debug.dumpStackTrace(trace.*);
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -158,19 +153,23 @@ pub fn handleRequest(request: *Request, zigRequestHandler: ZigRequestHandler) ?*
|
||||||
alloc,
|
alloc,
|
||||||
&zig_response,
|
&zig_response,
|
||||||
) catch |e| {
|
) catch |e| {
|
||||||
log.err("Unexpected error processing request: {any}", .{e});
|
logError("Unexpected error processing request: {any}", .{e}, @errorReturnTrace());
|
||||||
if (@errorReturnTrace()) |trace| {
|
|
||||||
std.debug.dumpStackTrace(trace.*);
|
|
||||||
}
|
|
||||||
if (zig_response.status == .ok) // this was an unexpected throw
|
if (zig_response.status == .ok) // this was an unexpected throw
|
||||||
zig_response.status = .internal_server_error;
|
zig_response.status = .internal_server_error;
|
||||||
return buildResponse(alloc, &zig_response);
|
return buildResponse(alloc, &zig_response);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Marshall data back for handling by server
|
// Marshall data back for handling by server
|
||||||
return buildResponse(alloc, &zig_response);
|
return buildResponse(alloc, &zig_response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn logError(comptime format: []const u8, args: anytype, stack_trace: anytype) void {
|
||||||
|
if (builtin.is_test) return;
|
||||||
|
log.err(format, args);
|
||||||
|
if (stack_trace) |trace| {
|
||||||
|
std.debug.dumpStackTrace(trace.*);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn buildResponse(alloc: std.mem.Allocator, zig_response: *ZigResponse) ?*Response {
|
fn buildResponse(alloc: std.mem.Allocator, zig_response: *ZigResponse) ?*Response {
|
||||||
var rc = alloc.create(Response) catch {
|
var rc = alloc.create(Response) catch {
|
||||||
log.err("Could not allocate memory for response object. This may be fatal", .{});
|
log.err("Could not allocate memory for response object. This may be fatal", .{});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user