@@ -6,7 +6,7 @@ const ErrorOld= global.Error;
66/*
77 * Replacig build-in Error, because of libraries we have not under control
88 * */
9- global . Error = class extends ErrorOld {
9+ globalThis . Error = class extends ErrorOld {
1010 static stackToList ( stack ) { return stack . split ( / ^ \s * a t \s / m) ; }
1111 static listToStack ( list ) { return list . map ( l => " at " + l ) . join ( "" ) ; }
1212 static exitCodeInfo ( exitCode ) { return exit_codes [ exitCode || - 1 ] ; }
@@ -17,6 +17,7 @@ global.Error= class extends ErrorOld{
1717 "h2 { color: magenta; }" ,
1818 "pre { color: gray; }" ,
1919 ) ;
20+ if ( ! e || typeof e . stack === "undefined" || typeof e . message === "undefined" ) e = new this ( e ) ;
2021 const { stdout, stderr, name, message, stack, exitCode= 1 } = e ;
2122 echo . use ( "-2" , `%c${ name } : ${ message . trim ( ) } ` , css . h1 ) ;
2223 echo . use ( "-2" , "%ccode: " + exitCode + ( Error . exitCodeInfo ( exitCode ) ? ` %c(${ Error . exitCodeInfo ( exitCode ) } )` : "%c" ) , css . h2 , "color: blue" ) ;
@@ -29,7 +30,8 @@ global.Error= class extends ErrorOld{
2930 super ( message , options ) ;
3031 const [ lm , ...l ] = Error . stackToList ( this . stack ) ;
3132 const i = l . findIndex ( l => l . indexOf ( "nodejsscript" ) === - 1 || l . indexOf ( "nodejsscript/examples" ) !== - 1 ) ;
32- const l_out = l . slice ( i ) . filter ( l => l . indexOf ( "node:internal" ) == - 1 && l . indexOf ( "nodejsscript/bin/cli.mjs" ) === - 1 && l . indexOf ( "async Promise.all (index 0)" ) === - 1 ) ;
33+ const l_out = l . slice ( i ) . filter ( l => ! l . includes ( "node:internal" ) && ! l . includes ( "nodejsscript/bin/" ) && ! l . includes ( "async Promise.all (index 0)" ) ) ;
34+ if ( ! l_out . length ) l_out . push ( process . argv [ 1 ] ) ;
3335 this . stack = lm + Error . listToStack ( l_out ) ;
3436 }
3537} ;
0 commit comments