From 4b9f6baf7909cfb68335fd1effd40f0e593f36fb Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Fri, 16 Sep 2022 22:50:46 -0700 Subject: [PATCH] Make `fetch` throw a `SystemError` on reject --- src/bun.js/webcore/response.zig | 16 +++++++--------- src/http_client_async.zig | 1 + 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/bun.js/webcore/response.zig b/src/bun.js/webcore/response.zig index 2ef8225f31..56d6fd5e38 100644 --- a/src/bun.js/webcore/response.zig +++ b/src/bun.js/webcore/response.zig @@ -583,15 +583,13 @@ pub const Fetch = struct { } pub fn onReject(this: *FetchTasklet) JSValue { - const fetch_error = std.fmt.allocPrint( - default_allocator, - "fetch() failed {s}\nurl: \"{s}\"", - .{ - this.result.fail, - this.result.href, - }, - ) catch unreachable; - return ZigString.init(fetch_error).toErrorInstance(this.global_this); + const fetch_error = JSC.SystemError{ + .code = ZigString.init(@errorName(this.result.fail)), + .message = ZigString.init("fetch() failed"), + .path = ZigString.init(this.http.?.url.href), + }; + + return fetch_error.toErrorInstance(this.global_this); } pub fn onResolve(this: *FetchTasklet) JSValue { diff --git a/src/http_client_async.zig b/src/http_client_async.zig index 9c6e848710..be63ff06e3 100644 --- a/src/http_client_async.zig +++ b/src/http_client_async.zig @@ -1638,6 +1638,7 @@ pub fn handleResponseBodyChunk( decoder.consume_trailer = 1; var bytes_decoded = incoming_data.len; + // phr_decode_chunked mutates in-place const pret = picohttp.phr_decode_chunked( decoder, buffer.list.items.ptr + (buffer.list.items.len - incoming_data.len),