Skip to content

[browser] only trace ExitStatus stack trace if diagnosticTracing is true #89432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 25, 2023
Merged
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
25 changes: 16 additions & 9 deletions src/mono/wasm/runtime/loader/exit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function mono_exit(exit_code: number, reason?: any): void {
mono_log_debug("abort_startup, reason: " + reason);
abort_promises(reason);
}
logErrorOnExit(exit_code, reason);
logOnExit(exit_code, reason);
appendElementOnExit(exit_code);
if (runtimeHelpers.jiterpreter_dump_stats) runtimeHelpers.jiterpreter_dump_stats(false);
if (exit_code === 0 && loaderHelpers.config?.interopCleanupOnExit) {
Expand Down Expand Up @@ -146,19 +146,26 @@ function appendElementOnExit(exit_code: number) {
}
}

function logErrorOnExit(exit_code: number, reason: any) {
function logOnExit(exit_code: number, reason: any) {
if (exit_code !== 0 && reason) {
if (reason instanceof Error) {
// ExitStatus usually is not real JS error and so stack strace is not very useful.
// We will use debug level for it, which will print only when diagnosticTracing is set.
const mono_log = runtimeHelpers.ExitStatus && reason instanceof runtimeHelpers.ExitStatus
? mono_log_debug
: mono_log_error;
if (typeof reason == "string") {
mono_log(reason);
}
else if (reason.stack && reason.message) {
if (runtimeHelpers.stringify_as_error_with_stack) {
mono_log_error(runtimeHelpers.stringify_as_error_with_stack(reason));
mono_log(runtimeHelpers.stringify_as_error_with_stack(reason));
} else {
mono_log_error(reason.message + "\n" + reason.stack);
mono_log(reason.message + "\n" + reason.stack);
}
}
else if (typeof reason == "string")
mono_log_error(reason);
else
mono_log_error(JSON.stringify(reason));
else {
mono_log(JSON.stringify(reason));
}
}
if (loaderHelpers.config && loaderHelpers.config.logExitCode) {
if (consoleWebSocket) {
Expand Down
4 changes: 2 additions & 2 deletions src/mono/wasm/runtime/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ export function mono_wasm_symbolicate_string(message: string): string {

export function mono_wasm_stringify_as_error_with_stack(err: Error | string): string {
let errObj: any = err;
if (!errObj || !errObj.stack || !(errObj instanceof Error)) {
errObj = new Error(errObj || "Unknown error");
if (!errObj || !errObj.stack) {
errObj = new Error(errObj ? ("" + errObj) : "Unknown error");
}

// Error
Expand Down