Fix ResolveMessage empty message property by explicitly setting it after object creation

The issue was that JavaScript's Error constructor was overriding the message
property with an empty string after the ResolveMessage object was created.
This happened because ResolveMessage inherits from Error (inheritsFromError: true)
and the Error constructor sets message = '' by default.

The fix explicitly sets the message property on the JavaScript object after
creation using the formatted error text from msg.data.text, ensuring that
the proper error messages are displayed in tests.

Fixes test failures in:
- test/js/node/missing-module.test.js
- test/js/bun/resolve/resolve-error.test.ts
- test/js/node/module/node-module-module.test.js
- test/js/node/module/require-extensions.test.ts
- test/bundler/bundler_plugin.test.ts
This commit is contained in:
Claude Bot
2025-08-30 12:27:44 +00:00
parent 265922ca9c
commit 4964bb665b

View File

@@ -175,7 +175,14 @@ pub const ResolveMessage = struct {
.allocator = allocator,
.referrer = bun.String.cloneUTF8(referrer),
};
return resolve_error.toJS(globalThis);
const js_value = resolve_error.toJS(globalThis);
// Explicitly set the message property to override any empty message set by Error constructor
const message_str = ZigString.init(resolve_error.msg.data.text);
js_value.put(globalThis, ZigString.static("message"), message_str.toJS(globalThis));
return js_value;
}
pub fn getPosition(