fix: add a better error message for fetch when it fails with an unknown code (#9663)

* add a better error message for fetch when it fails with an unknown code

* Update src/bun.js/webcore/response.zig

Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>

* [autofix.ci] apply automated fixes

* fix compilation

---------

Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
dave caruso
2024-03-29 14:18:11 -07:00
committed by GitHub
parent e80e61c9a3
commit 3047c9005e
3 changed files with 49 additions and 1 deletions

View File

@@ -0,0 +1,36 @@
//! This file is generated by src/codegen/js2native-generator.ts based on seen calls to the $zig() JS macro
const JSC = @import("root").bun.JSC;
export fn JS2Zig__createBinding_workaround(global: u64) callconv(.C) JSC.JSValue {
return @import("../node/node_fs_binding.zig").createBinding(@ptrFromInt(global));
}
export fn JS2Zig__createNodeHttp_Binding_workaround(global: u64) callconv(.C) JSC.JSValue {
return @import("../api/bun/h2_frame_parser.zig").createNodeHttp2Binding(@ptrFromInt(global));
}
export fn JS2Zig__OS_create_workaround(global: u64) callconv(.C) JSC.JSValue {
return @import("../node/node_os.zig").OS.create(@ptrFromInt(global));
}
export fn JS2Zig__String_jsGetStringWidth(global: *JSC.JSGlobalObject, call_frame: *JSC.CallFrame) callconv(.C) JSC.JSValue {
return @import("../../string.zig").String.jsGetStringWidth(global, call_frame);
}
export fn JS2Zig__parseArgs(global: *JSC.JSGlobalObject, call_frame: *JSC.CallFrame) callconv(.C) JSC.JSValue {
return @import("../node/util/parse_args.zig").parseArgs(global, call_frame);
}
export fn JS2Zig__QuickAndDirtyJavaScriptSyntaxHighlighter_jsFunctionSyntaxHighlight(global: *JSC.JSGlobalObject, call_frame: *JSC.CallFrame) callconv(.C) JSC.JSValue {
return @import("../../fmt.zig").QuickAndDirtyJavaScriptSyntaxHighlighter.jsFunctionSyntaxHighlight(global, call_frame);
}
export fn JS2Zig__TestingAPIs_shellLex(global: *JSC.JSGlobalObject, call_frame: *JSC.CallFrame) callconv(.C) JSC.JSValue {
return @import("../../shell/shell.zig").TestingAPIs.shellLex(global, call_frame);
}
export fn JS2Zig__TestingAPIs_shellParse(global: *JSC.JSGlobalObject, call_frame: *JSC.CallFrame) callconv(.C) JSC.JSValue {
return @import("../../shell/shell.zig").TestingAPIs.shellParse(global, call_frame);
}
comptime {
_ = &JS2Zig__createBinding_workaround;
_ = &JS2Zig__createNodeHttp_Binding_workaround;
_ = &JS2Zig__OS_create_workaround;
_ = &JS2Zig__String_jsGetStringWidth;
_ = &JS2Zig__parseArgs;
_ = &JS2Zig__QuickAndDirtyJavaScriptSyntaxHighlighter_jsFunctionSyntaxHighlight;
_ = &JS2Zig__TestingAPIs_shellLex;
_ = &JS2Zig__TestingAPIs_shellParse;
}

View File

@@ -1304,7 +1304,11 @@ pub const Fetch = struct {
error.STORE_LOOKUP => bun.String.static("Issuer certificate lookup error"),
error.NAME_CONSTRAINTS_WITHOUT_SANS => bun.String.static("Issuer has name constraints but leaf has no SANs"),
error.UNKKNOW_CERTIFICATE_VERIFICATION_ERROR => bun.String.static("unknown certificate verification error"),
else => bun.String.static("fetch() failed. For more information, pass `verbose: true` in the second argument to fetch()"),
else => |e| bun.String.createFormat("{s} fetching \"{}\". For more information, pass `verbose: true` in the second argument to fetch()", .{
@errorName(e),
path,
}) catch bun.outOfMemory(),
},
.path = path,
};

View File

@@ -397,6 +397,14 @@ pub const String = extern struct {
return BunString__fromUTF16(bytes.ptr, bytes.len);
}
pub fn createFormat(comptime fmt: []const u8, args: anytype) !String {
var sba = std.heap.stackFallback(16384, bun.default_allocator);
const alloc = sba.get();
const buf = try std.fmt.allocPrint(alloc, fmt, args);
defer alloc.free(buf);
return createUTF8(buf);
}
pub fn createFromOSPath(os_path: bun.OSPathSlice) String {
return switch (@TypeOf(os_path)) {
[]const u8 => createUTF8(os_path),