mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
Fix Bun.serve error handler error param (#1359)
This commit is contained in:
@@ -1460,6 +1460,15 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
|
||||
}
|
||||
|
||||
if (response_value.isError() or response_value.isAggregateError(this.globalThis) or response_value.isException(this.globalThis.vm())) {
|
||||
// cast exception to error instance
|
||||
if (response_value.isException(this.globalThis.vm())) {
|
||||
const err = response_value.toError(this.globalThis);
|
||||
if (!err.isUndefinedOrNull()) {
|
||||
ctx.runErrorHandler(err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ctx.runErrorHandler(response_value);
|
||||
|
||||
return;
|
||||
|
||||
@@ -2556,6 +2556,20 @@ void JSC__JSValue__getNameProperty(JSC__JSValue JSValue0, JSC__JSGlobalObject* a
|
||||
arg2->len = 0;
|
||||
}
|
||||
|
||||
JSC__JSValue JSC__JSValue__toError(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1)
|
||||
{
|
||||
JSC::JSValue value = JSC::JSValue::decode(JSValue0);
|
||||
if (JSC::Exception* jscException = JSC::jsDynamicCast<JSC::Exception*>(value)) {
|
||||
if (JSC::ErrorInstance* error = JSC::jsDynamicCast<JSC::ErrorInstance*>(jscException->value())) {
|
||||
return JSC::JSValue::encode(JSC::JSValue(error));
|
||||
}
|
||||
}
|
||||
if (JSC::ErrorInstance* error = JSC::jsDynamicCast<JSC::ErrorInstance*>(value)) {
|
||||
return JSC::JSValue::encode(JSC::JSValue(error));
|
||||
}
|
||||
return JSC::JSValue::encode(JSC::jsUndefined());
|
||||
}
|
||||
|
||||
void JSC__JSValue__toZigException(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1,
|
||||
ZigException* exception)
|
||||
{
|
||||
|
||||
@@ -3136,6 +3136,10 @@ pub const JSValue = enum(JSValueReprInt) {
|
||||
return cppFn("isTerminationException", .{ this, vm });
|
||||
}
|
||||
|
||||
pub fn toError(this: JSValue, global: *JSGlobalObject) JSValue {
|
||||
return cppFn("toError", .{ this, global });
|
||||
}
|
||||
|
||||
pub fn toZigException(this: JSValue, global: *JSGlobalObject, exception: *ZigException) void {
|
||||
return cppFn("toZigException", .{ this, global, exception });
|
||||
}
|
||||
@@ -3493,7 +3497,7 @@ pub const JSValue = enum(JSValueReprInt) {
|
||||
return this.asNullableVoid().?;
|
||||
}
|
||||
|
||||
pub const Extern = [_][]const u8{ "fastGet_", "getStaticProperty", "createUninitializedUint8Array", "fromInt64NoTruncate", "fromUInt64NoTruncate", "toUInt64NoTruncate", "asPromise", "toInt64", "_then", "put", "makeWithNameAndPrototype", "parseJSON", "symbolKeyFor", "symbolFor", "getSymbolDescription", "createInternalPromise", "asInternalPromise", "asArrayBuffer_", "fromEntries", "createTypeError", "createRangeError", "createObject2", "getIfPropertyExistsImpl", "jsType", "jsonStringify", "kind_", "isTerminationException", "isSameValue", "getLengthOfArray", "toZigString", "createStringArray", "createEmptyObject", "putRecord", "asPromise", "isClass", "getNameProperty", "getClassName", "getErrorsProperty", "toInt32", "toBoolean", "isInt32", "isIterable", "forEach", "isAggregateError", "toZigException", "isException", "toWTFString", "hasProperty", "getPropertyNames", "getDirect", "putDirect", "getIfExists", "asString", "asObject", "asNumber", "isError", "jsNull", "jsUndefined", "jsTDZValue", "jsBoolean", "jsDoubleNumber", "jsNumberFromDouble", "jsNumberFromChar", "jsNumberFromU16", "jsNumberFromInt64", "isBoolean", "isAnyInt", "isUInt32AsAnyInt", "isInt32AsAnyInt", "isNumber", "isString", "isBigInt", "isHeapBigInt", "isBigInt32", "isSymbol", "isPrimitive", "isGetterSetter", "isCustomGetterSetter", "isObject", "isCell", "asCell", "toString", "toStringOrNull", "toPropertyKey", "toPropertyKeyValue", "toObject", "toString", "getPrototype", "getPropertyByPropertyName", "eqlValue", "eqlCell", "isCallable" };
|
||||
pub const Extern = [_][]const u8{ "fastGet_", "getStaticProperty", "createUninitializedUint8Array", "fromInt64NoTruncate", "fromUInt64NoTruncate", "toUInt64NoTruncate", "asPromise", "toInt64", "_then", "put", "makeWithNameAndPrototype", "parseJSON", "symbolKeyFor", "symbolFor", "getSymbolDescription", "createInternalPromise", "asInternalPromise", "asArrayBuffer_", "fromEntries", "createTypeError", "createRangeError", "createObject2", "getIfPropertyExistsImpl", "jsType", "jsonStringify", "kind_", "isTerminationException", "isSameValue", "getLengthOfArray", "toZigString", "createStringArray", "createEmptyObject", "putRecord", "asPromise", "isClass", "getNameProperty", "getClassName", "getErrorsProperty", "toInt32", "toBoolean", "isInt32", "isIterable", "forEach", "isAggregateError", "toError", "toZigException", "isException", "toWTFString", "hasProperty", "getPropertyNames", "getDirect", "putDirect", "getIfExists", "asString", "asObject", "asNumber", "isError", "jsNull", "jsUndefined", "jsTDZValue", "jsBoolean", "jsDoubleNumber", "jsNumberFromDouble", "jsNumberFromChar", "jsNumberFromU16", "jsNumberFromInt64", "isBoolean", "isAnyInt", "isUInt32AsAnyInt", "isInt32AsAnyInt", "isNumber", "isString", "isBigInt", "isHeapBigInt", "isBigInt32", "isSymbol", "isPrimitive", "isGetterSetter", "isCustomGetterSetter", "isObject", "isCell", "asCell", "toString", "toStringOrNull", "toPropertyKey", "toPropertyKeyValue", "toObject", "toString", "getPrototype", "getPropertyByPropertyName", "eqlValue", "eqlCell", "isCallable" };
|
||||
};
|
||||
|
||||
extern "c" fn Microtask__run(*Microtask, *JSGlobalObject) void;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//-- AUTOGENERATED FILE -- 1665449441
|
||||
//-- AUTOGENERATED FILE -- 1666254195
|
||||
// clang-format off
|
||||
#pragma once
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// clang-format off
|
||||
//-- AUTOGENERATED FILE -- 1665449441
|
||||
//-- AUTOGENERATED FILE -- 1666254195
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
@@ -541,6 +541,7 @@ CPP_DECL void JSC__JSValue__putRecord(JSC__JSValue JSValue0, JSC__JSGlobalObject
|
||||
CPP_DECL JSC__JSValue JSC__JSValue__symbolFor(JSC__JSGlobalObject* arg0, ZigString* arg1);
|
||||
CPP_DECL bool JSC__JSValue__symbolKeyFor(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, ZigString* arg2);
|
||||
CPP_DECL bool JSC__JSValue__toBoolean(JSC__JSValue JSValue0);
|
||||
CPP_DECL JSC__JSValue JSC__JSValue__toError(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1);
|
||||
CPP_DECL int32_t JSC__JSValue__toInt32(JSC__JSValue JSValue0);
|
||||
CPP_DECL int64_t JSC__JSValue__toInt64(JSC__JSValue JSValue0);
|
||||
CPP_DECL JSC__JSObject* JSC__JSValue__toObject(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1);
|
||||
|
||||
@@ -334,6 +334,7 @@ pub extern fn JSC__JSValue__putRecord(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlo
|
||||
pub extern fn JSC__JSValue__symbolFor(arg0: ?*JSC__JSGlobalObject, arg1: [*c]ZigString) JSC__JSValue;
|
||||
pub extern fn JSC__JSValue__symbolKeyFor(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject, arg2: [*c]ZigString) bool;
|
||||
pub extern fn JSC__JSValue__toBoolean(JSValue0: JSC__JSValue) bool;
|
||||
pub extern fn JSC__JSValue__toError(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject) JSC__JSValue;
|
||||
pub extern fn JSC__JSValue__toInt32(JSValue0: JSC__JSValue) i32;
|
||||
pub extern fn JSC__JSValue__toInt64(JSValue0: JSC__JSValue) i64;
|
||||
pub extern fn JSC__JSValue__toObject(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject) [*c]JSC__JSObject;
|
||||
|
||||
@@ -206,18 +206,20 @@ describe("streaming", () => {
|
||||
var server;
|
||||
try {
|
||||
var pass = false;
|
||||
var err = { name: '', message: '' };
|
||||
server = serve({
|
||||
port: port++,
|
||||
development: false,
|
||||
error(e) {
|
||||
pass = true;
|
||||
err = e;
|
||||
return new Response("Fail", { status: 500 });
|
||||
},
|
||||
fetch(req) {
|
||||
return new Response(
|
||||
new ReadableStream({
|
||||
start(controller) {
|
||||
throw new Error("error");
|
||||
throw new TypeError("error");
|
||||
},
|
||||
})
|
||||
);
|
||||
@@ -228,6 +230,8 @@ describe("streaming", () => {
|
||||
expect(response.status).toBe(500);
|
||||
expect(await response.text()).toBe("Fail");
|
||||
expect(pass).toBe(true);
|
||||
expect(err.name).toBe("TypeError");
|
||||
expect(err.message).toBe("error");
|
||||
} catch (e) {
|
||||
throw e;
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user