@@ -49,7 +49,7 @@ export function mono_exit(exit_code: number, reason?: any): void {
49
49
mono_log_debug ( "abort_startup, reason: " + reason ) ;
50
50
abort_promises ( reason ) ;
51
51
}
52
- logErrorOnExit ( exit_code , reason ) ;
52
+ logOnExit ( exit_code , reason ) ;
53
53
appendElementOnExit ( exit_code ) ;
54
54
if ( runtimeHelpers . jiterpreter_dump_stats ) runtimeHelpers . jiterpreter_dump_stats ( false ) ;
55
55
if ( exit_code === 0 && loaderHelpers . config ?. interopCleanupOnExit ) {
@@ -146,19 +146,26 @@ function appendElementOnExit(exit_code: number) {
146
146
}
147
147
}
148
148
149
- function logErrorOnExit ( exit_code : number , reason : any ) {
149
+ function logOnExit ( exit_code : number , reason : any ) {
150
150
if ( exit_code !== 0 && reason ) {
151
- if ( reason instanceof Error ) {
151
+ // ExitStatus usually is not real JS error and so stack strace is not very useful.
152
+ // We will use debug level for it, which will print only when diagnosticTracing is set.
153
+ const mono_log = runtimeHelpers . ExitStatus && reason instanceof runtimeHelpers . ExitStatus
154
+ ? mono_log_debug
155
+ : mono_log_error ;
156
+ if ( typeof reason == "string" ) {
157
+ mono_log ( reason ) ;
158
+ }
159
+ else if ( reason . stack && reason . message ) {
152
160
if ( runtimeHelpers . stringify_as_error_with_stack ) {
153
- mono_log_error ( runtimeHelpers . stringify_as_error_with_stack ( reason ) ) ;
161
+ mono_log ( runtimeHelpers . stringify_as_error_with_stack ( reason ) ) ;
154
162
} else {
155
- mono_log_error ( reason . message + "\n" + reason . stack ) ;
163
+ mono_log ( reason . message + "\n" + reason . stack ) ;
156
164
}
157
165
}
158
- else if ( typeof reason == "string" )
159
- mono_log_error ( reason ) ;
160
- else
161
- mono_log_error ( JSON . stringify ( reason ) ) ;
166
+ else {
167
+ mono_log ( JSON . stringify ( reason ) ) ;
168
+ }
162
169
}
163
170
if ( loaderHelpers . config && loaderHelpers . config . logExitCode ) {
164
171
if ( consoleWebSocket ) {
0 commit comments