Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use error handling callback in more places, emit 1015 when WSS TLS handshaking fails, micro-optimize ServerWebSocket, fix bug in util.inspect exceptions #10633

Merged
merged 12 commits into from
Apr 29, 2024
Merged
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@
"**/*.xcscheme": true,
"**/*.xcodeproj": true,
"**/*.i": true,

// uws WebSocket.cpp conflicts with webcore WebSocket.cpp
"packages/bun-uws/fuzzing": true,
},
"files.associations": {
"*.idl": "cpp",
Expand Down
11 changes: 11 additions & 0 deletions src/bun.js/ConsoleObject.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1817,12 +1817,14 @@ pub const Formatter = struct {
}

extern fn JSC__JSValue__callCustomInspectFunction(
*JSC.JSGlobalObject,
*JSC.JSGlobalObject,
JSValue,
JSValue,
depth: u32,
max_depth: u32,
colors: bool,
is_exception: *bool,
) JSValue;

pub fn printAs(
Expand Down Expand Up @@ -2001,16 +2003,25 @@ pub const Formatter = struct {
writer.print(comptime Output.prettyFmt("<r><yellow>null<r>", enable_ansi_colors), .{});
},
.CustomFormattedObject => {
var is_exception = false;
// Call custom inspect function. Will return the error if there is one
// we'll need to pass the callback through to the "this" value in here
const result = JSC__JSValue__callCustomInspectFunction(
JSC.VirtualMachine.get().global,
this.globalThis,
this.custom_formatted_object.function,
this.custom_formatted_object.this,
this.max_depth -| this.depth,
this.max_depth,
enable_ansi_colors,
&is_exception,
);
if (is_exception) {
// Previously, this printed [native code]
// TODO: in the future, should this throw when in Bun.inspect?
writer.print("[custom formatter threw an exception]", .{});
return;
}
// Strings are printed directly, otherwise we recurse. It is possible to end up in an infinite loop.
if (result.isString()) {
writer.print("{}", .{result.fmtString(this.globalThis)});
Expand Down
8 changes: 4 additions & 4 deletions src/bun.js/api/BunObject.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3685,7 +3685,7 @@ pub const Timer = struct {
}

var this = args.ptr[1].asPtr(CallbackJob);
globalThis.bunVM().onUnhandledError(globalThis, args.ptr[0]);
globalThis.bunVM().onError(globalThis, args.ptr[0]);
this.deinit();
return JSValue.jsUndefined();
}
Expand Down Expand Up @@ -3787,7 +3787,7 @@ pub const Timer = struct {
}

if (result.isAnyError()) {
vm.onUnhandledError(globalThis, result);
vm.onError(globalThis, result);
this.deinit();
return;
}
Expand All @@ -3796,7 +3796,7 @@ pub const Timer = struct {
switch (promise.status(globalThis.vm())) {
.Rejected => {
this.deinit();
vm.onUnhandledError(globalThis, promise.result(globalThis.vm()));
vm.onError(globalThis, promise.result(globalThis.vm()));
},
.Fulfilled => {
this.deinit();
Expand Down Expand Up @@ -5265,7 +5265,7 @@ pub const EnvironmentVariables = struct {
};

export fn Bun__reportError(globalObject: *JSGlobalObject, err: JSC.JSValue) void {
JSC.VirtualMachine.runErrorHandlerWithDedupe(globalObject.bunVM(), err, null);
JSC.VirtualMachine.get().onError(globalObject, err);
}

comptime {
Expand Down
4 changes: 2 additions & 2 deletions src/bun.js/api/bun/socket.zig
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,14 @@ const Handlers = struct {
const onError = this.onError;
if (onError == .zero) {
if (err.len > 0)
this.vm.onUnhandledError(this.globalObject, err[0]);
this.vm.onError(this.globalObject, err[0]);

return false;
}

const result = onError.callWithThis(this.globalObject, thisValue, err);
if (result.isAnyError()) {
this.vm.onUnhandledError(this.globalObject, result);
this.vm.onError(this.globalObject, result);
}

return true;
Expand Down
4 changes: 2 additions & 2 deletions src/bun.js/api/bun/udp_socket.zig
Original file line number Diff line number Diff line change
Expand Up @@ -355,14 +355,14 @@ pub const UDPSocket = struct {

if (callback == .zero) {
if (err.len > 0)
vm.onUnhandledError(globalThis, err[0]);
vm.onError(globalThis, err[0]);

return false;
}

const result = callback.callWithThis(globalThis, thisValue, err);
if (result.isAnyError()) {
vm.onUnhandledError(globalThis, result);
vm.onError(globalThis, result);
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/api/html_rewriter.zig
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ fn HandlerCallback(
this.global.bunVM().waitForPromise(promise);
const fail = promise.status(this.global.vm()) == .Rejected;
if (fail) {
this.global.bunVM().runErrorHandler(promise.result(this.global.vm()), null);
this.global.bunVM().onError(this.global, promise.result(this.global.vm()));
}
return fail;
}
Expand Down
Loading
Loading