From 94bf404c417f2b6ecb716679d86ed47e26fb157a Mon Sep 17 00:00:00 2001 From: Dylan Conway <35280289+dylan-conway@users.noreply.github.com> Date: Thu, 2 May 2024 15:06:14 -0700 Subject: [PATCH] Print bun version on unhandled errors (#10760) Co-authored-by: dave caruso --- src/Global.zig | 8 ++++++++ src/bun.js/bindings/BunProcess.cpp | 3 +++ src/bun_js.zig | 18 ++++++++++++++++++ test/bundler/expectBundled.ts | 2 ++ test/js/bun/util/reportError.test.ts | 5 ++++- 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/Global.zig b/src/Global.zig index 58e0acf845..0ec22d9b81 100644 --- a/src/Global.zig +++ b/src/Global.zig @@ -50,6 +50,14 @@ else pub const os_name = Environment.os.nameString(); +// Bun v1.0.0 (Linux x64 baseline) +// Bun v1.0.0-debug (Linux x64) +// Bun v1.0.0-canary.0+44e09bb7f (Linux x64) +pub const unhandled_error_bun_version_string = "Bun v" ++ + (if (Environment.is_canary) package_json_version_with_revision else package_json_version) ++ + " (" ++ Environment.os.displayString() ++ " " ++ arch_name ++ + (if (Environment.baseline) " baseline)" else ")"); + pub const arch_name = if (Environment.isX64) "x64" else if (Environment.isX86) diff --git a/src/bun.js/bindings/BunProcess.cpp b/src/bun.js/bindings/BunProcess.cpp index 9e0ea601a6..fa4d8aecc3 100644 --- a/src/bun.js/bindings/BunProcess.cpp +++ b/src/bun.js/bindings/BunProcess.cpp @@ -181,6 +181,9 @@ static JSValue constructVersions(VM& vm, JSObject* processObject) #endif object->putDirect(vm, JSC::Identifier::fromString(vm, "napi"_s), JSValue(JSC::jsString(vm, makeString("9"_s))), 0); + object->putDirect(vm, JSC::Identifier::fromString(vm, "icu"_s), JSValue(JSC::jsString(vm, makeString(U_ICU_VERSION))), 0); + object->putDirect(vm, JSC::Identifier::fromString(vm, "unicode"_s), JSValue(JSC::jsString(vm, makeString(U_UNICODE_VERSION))), 0); + object->putDirect(vm, JSC::Identifier::fromString(vm, "modules"_s), JSC::JSValue(JSC::jsString(vm, makeAtomString("115")))); diff --git a/src/bun_js.zig b/src/bun_js.zig index 67c87eb16f..f54e28413e 100644 --- a/src/bun_js.zig +++ b/src/bun_js.zig @@ -282,6 +282,13 @@ pub const Run = struct { } else { vm.exit_handler.exit_code = 1; vm.onExit(); + + if (run.any_unhandled) { + Output.prettyErrorln( + "\n{s}", + .{Global.unhandled_error_bun_version_string}, + ); + } Global.exit(1); } } @@ -307,6 +314,12 @@ pub const Run = struct { } else { vm.exit_handler.exit_code = 1; vm.onExit(); + if (run.any_unhandled) { + Output.prettyErrorln( + "\n{s}", + .{Global.unhandled_error_bun_version_string}, + ); + } Global.exit(1); } } @@ -403,6 +416,11 @@ pub const Run = struct { vm.global.handleRejectedPromises(); if (this.any_unhandled and this.vm.exit_handler.exit_code == 0) { this.vm.exit_handler.exit_code = 1; + + Output.prettyErrorln( + "\n{s}", + .{Global.unhandled_error_bun_version_string}, + ); } const exit_code = this.vm.exit_handler.exit_code; diff --git a/test/bundler/expectBundled.ts b/test/bundler/expectBundled.ts index 0af0e6f55d..a28dbcc3f9 100644 --- a/test/bundler/expectBundled.ts +++ b/test/bundler/expectBundled.ts @@ -1294,6 +1294,8 @@ for (const [key, blob] of build.outputs) { const lines = stderr! .toUnixString() .split("\n") + // remove `Bun v1.0.0...` line + .slice(0, -2) .filter(Boolean) .map(x => x.trim()) .reverse(); diff --git a/test/js/bun/util/reportError.test.ts b/test/js/bun/util/reportError.test.ts index f6520b90b7..73a96aebc9 100644 --- a/test/js/bun/util/reportError.test.ts +++ b/test/js/bun/util/reportError.test.ts @@ -14,6 +14,9 @@ test("reportError", () => { BUN_JSC_showPrivateScriptsInStackTraces: "0", }, }); - const output = stderr.toString().replaceAll(cwd, "").replaceAll("\\", "/"); + let output = stderr.toString().replaceAll(cwd, "").replaceAll("\\", "/"); + // remove bun version from output + output = output.split("\n").slice(0, -2).join("\n"); + expect(output).toMatchSnapshot(); });