Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions src/jsc/JSGlobalObject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -939,12 +939,7 @@ impl JSGlobalObject {
debug_assert!(error_array.is_array());
let message = BunString::create_format(message);
crate::from_js_host_call(self, || {
JSC__JSGlobalObject__createAggregateErrorWithArray(
self,
error_array,
&message,
JSValue::UNDEFINED,
)
JSC__JSGlobalObject__createAggregateErrorWithArray(self, error_array, &message)
})
}

Expand Down Expand Up @@ -1542,7 +1537,6 @@ unsafe extern "C" {
global: &JSGlobalObject,
error_array: JSValue,
message: &BunString,
options: JSValue,
) -> JSValue;
safe fn JSC__JSGlobalObject__generateHeapSnapshot(this: &JSGlobalObject) -> JSValue;

Expand Down
2 changes: 1 addition & 1 deletion src/jsc/bindings/ErrorCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ JSC::EncodedJSValue INVALID_ARG_VALUE_RangeError(JSC::ThrowScope& throwScope, JS
RELEASE_RETURN_IF_EXCEPTION(throwScope, {});

auto* structure = createErrorStructure(vm, globalObject, ErrorType::RangeError, "RangeError"_s, "ERR_INVALID_ARG_VALUE"_s);
auto error = JSC::ErrorInstance::create(vm, structure, message, jsUndefined(), nullptr, JSC::RuntimeType::TypeNothing, ErrorType::RangeError, true);
auto error = JSC::ErrorInstance::create(vm, structure, message, JSValue(), nullptr, JSC::RuntimeType::TypeNothing, ErrorType::RangeError, true);
throwScope.throwException(globalObject, error);
throwScope.release();
return {};
Expand Down
7 changes: 3 additions & 4 deletions src/jsc/bindings/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3728,7 +3728,6 @@ JSC::EncodedJSValue JSC__JSGlobalObject__createAggregateError(JSC::JSGlobalObjec
auto scope = DECLARE_THROW_SCOPE(vm);

WTF::String message = arg3->toWTFString();
JSC::JSValue cause = JSC::jsUndefined();
JSC::JSArray* array = nullptr;
{
JSC::ObjectInitializationScope initializationScope(vm);
Expand All @@ -3749,14 +3748,14 @@ JSC::EncodedJSValue JSC__JSGlobalObject__createAggregateError(JSC::JSGlobalObjec

JSC::Structure* errorStructure = globalObject->errorStructure(JSC::ErrorType::AggregateError);

RELEASE_AND_RETURN(scope, JSC::JSValue::encode(JSC::createAggregateError(vm, errorStructure, array, message, cause, nullptr, JSC::TypeNothing, false)));
RELEASE_AND_RETURN(scope, JSC::JSValue::encode(JSC::createAggregateError(vm, errorStructure, array, message, JSC::JSValue(), nullptr, JSC::TypeNothing, false)));
}
JSC::EncodedJSValue JSC__JSGlobalObject__createAggregateErrorWithArray(JSC::JSGlobalObject* global, JSC::JSArray* array, const BunString* message, JSValue cause)
JSC::EncodedJSValue JSC__JSGlobalObject__createAggregateErrorWithArray(JSC::JSGlobalObject* global, JSC::JSArray* array, const BunString* message)
{
auto& vm = JSC::getVM(global);
JSC::Structure* errorStructure = global->errorStructure(JSC::ErrorType::AggregateError);
WTF::String messageString = message->toWTFString();
return JSC::JSValue::encode(JSC::createAggregateError(vm, errorStructure, array, messageString, cause, nullptr, JSC::TypeNothing, false));
return JSC::JSValue::encode(JSC::createAggregateError(vm, errorStructure, array, messageString, JSC::JSValue(), nullptr, JSC::TypeNothing, false));
}

// This must be a globally allocated string
Expand Down
21 changes: 21 additions & 0 deletions test/js/bun/util/inspect-error.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,27 @@ describe("observable properties", () => {
}
});

// util.inspect prints `[cause]: undefined` for an own `cause` that is undefined.
test("an error that bun creates without a cause has no own cause", async () => {
const thrown = async run => {
try {
await run();
} catch (error) {
return error;
}
};
const errors = [
await thrown(() => process.cpuUsage({ user: -1, system: 0 })),
await thrown(() => new Bun.Transpiler().transformSync("export function f() {\n const v = {b: {},),r,};\n}\n")),
await thrown(() => Bun.build({ entrypoints: ["/broken.js"], files: { "/broken.js": "const a = ;" } })),
];
expect(errors.map(error => [error?.name, Object.hasOwn(error ?? {}, "cause")])).toEqual([
["RangeError", false],
["AggregateError", false],
["AggregateError", false],
]);
});

describe("error.code is a String object that has no primitive value", () => {
const codes = {
"toString throws": `Object.assign(new String("E_X"), { toString() { throw new Error("toString threw"); } })`,
Expand Down
Loading