@@ -431,59 +431,66 @@ function REPLServer(prompt,
431431 ( { processTopLevelAwait } = require ( 'internal/repl/await' ) ) ;
432432 }
433433
434- const potentialWrappedCode = processTopLevelAwait ( code ) ;
435- if ( potentialWrappedCode !== null ) {
436- code = potentialWrappedCode ;
437- wrappedCmd = true ;
438- awaitPromise = true ;
434+ try {
435+ const potentialWrappedCode = processTopLevelAwait ( code ) ;
436+ if ( potentialWrappedCode !== null ) {
437+ code = potentialWrappedCode ;
438+ wrappedCmd = true ;
439+ awaitPromise = true ;
440+ }
441+ } catch ( e ) {
442+ decorateErrorStack ( e ) ;
443+ err = e ;
439444 }
440445 }
441446
442447 // First, create the Script object to check the syntax
443448 if ( code === '\n' )
444449 return cb ( null ) ;
445450
446- let parentURL ;
447- try {
448- const { pathToFileURL } = require ( 'url' ) ;
449- // Adding `/repl` prevents dynamic imports from loading relative
450- // to the parent of `process.cwd()`.
451- parentURL = pathToFileURL ( path . join ( process . cwd ( ) , 'repl' ) ) . href ;
452- } catch {
453- }
454- while ( true ) {
451+ if ( err === null ) {
452+ let parentURL ;
455453 try {
456- if ( self . replMode === module . exports . REPL_MODE_STRICT &&
457- ! RegExpPrototypeTest ( / ^ \s * $ / , code ) ) {
458- // "void 0" keeps the repl from returning "use strict" as the result
459- // value for statements and declarations that don't return a value.
460- code = `'use strict'; void 0;\n${ code } ` ;
461- }
462- script = vm . createScript ( code , {
463- filename : file ,
464- displayErrors : true ,
465- importModuleDynamically : async ( specifier ) => {
466- return asyncESM . ESMLoader . import ( specifier , parentURL ) ;
454+ const { pathToFileURL } = require ( 'url' ) ;
455+ // Adding `/repl` prevents dynamic imports from loading relative
456+ // to the parent of `process.cwd()`.
457+ parentURL = pathToFileURL ( path . join ( process . cwd ( ) , 'repl' ) ) . href ;
458+ } catch {
459+ }
460+ while ( true ) {
461+ try {
462+ if ( self . replMode === module . exports . REPL_MODE_STRICT &&
463+ ! RegExpPrototypeTest ( / ^ \s * $ / , code ) ) {
464+ // "void 0" keeps the repl from returning "use strict" as the result
465+ // value for statements and declarations that don't return a value.
466+ code = `'use strict'; void 0;\n${ code } ` ;
467467 }
468- } ) ;
469- } catch ( e ) {
470- debug ( 'parse error %j' , code , e ) ;
471- if ( wrappedCmd ) {
472- // Unwrap and try again
473- wrappedCmd = false ;
474- awaitPromise = false ;
475- code = input ;
476- wrappedErr = e ;
477- continue ;
468+ script = vm . createScript ( code , {
469+ filename : file ,
470+ displayErrors : true ,
471+ importModuleDynamically : async ( specifier ) => {
472+ return asyncESM . ESMLoader . import ( specifier , parentURL ) ;
473+ }
474+ } ) ;
475+ } catch ( e ) {
476+ debug ( 'parse error %j' , code , e ) ;
477+ if ( wrappedCmd ) {
478+ // Unwrap and try again
479+ wrappedCmd = false ;
480+ awaitPromise = false ;
481+ code = input ;
482+ wrappedErr = e ;
483+ continue ;
484+ }
485+ // Preserve original error for wrapped command
486+ const error = wrappedErr || e ;
487+ if ( isRecoverableError ( error , code ) )
488+ err = new Recoverable ( error ) ;
489+ else
490+ err = error ;
478491 }
479- // Preserve original error for wrapped command
480- const error = wrappedErr || e ;
481- if ( isRecoverableError ( error , code ) )
482- err = new Recoverable ( error ) ;
483- else
484- err = error ;
492+ break ;
485493 }
486- break ;
487494 }
488495
489496 // This will set the values from `savedRegExMatches` to corresponding
0 commit comments