Print bun version on unhandled errors (#10760)

Co-authored-by: dave caruso <me@paperdave.net>
This commit is contained in:
Dylan Conway
2024-05-02 15:06:14 -07:00
committed by GitHub
parent d66a4fc0f4
commit 94bf404c41
5 changed files with 35 additions and 1 deletions

View File

@@ -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)

View File

@@ -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"))));

View File

@@ -282,6 +282,13 @@ pub const Run = struct {
} else {
vm.exit_handler.exit_code = 1;
vm.onExit();
if (run.any_unhandled) {
Output.prettyErrorln(
"<r>\n<d>{s}<r>",
.{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(
"<r>\n<d>{s}<r>",
.{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(
"<r>\n<d>{s}<r>",
.{Global.unhandled_error_bun_version_string},
);
}
const exit_code = this.vm.exit_handler.exit_code;

View File

@@ -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();

View File

@@ -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();
});