@@ -4,7 +4,7 @@ import { CdkToolkit, AssetBuildTime } from './cdk-toolkit';
44import { ciSystemIsStdErrSafe } from './ci-systems' ;
55import { parseCommandLineArguments } from './parse-command-line-arguments' ;
66import { checkForPlatformWarnings } from './platform-warnings' ;
7-
7+ import { prettyPrintError } from './pretty-print-error' ;
88import * as version from './version' ;
99import { asIoHelper } from '../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private' ;
1010import { SdkProvider } from '../api/aws-auth' ;
@@ -28,7 +28,6 @@ import { docs } from '../commands/docs';
2828import { doctor } from '../commands/doctor' ;
2929import { getMigrateScanType } from '../commands/migrate' ;
3030import { cliInit , printAvailableTemplates } from '../init' ;
31- import { result , debug , error , info } from '../logging' ;
3231import { Notices } from '../notices' ;
3332import type { Command } from './user-configuration' ;
3433import { Configuration } from './user-configuration' ;
@@ -82,11 +81,11 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise<n
8281 try {
8382 await checkForPlatformWarnings ( ) ;
8483 } catch ( e ) {
85- debug ( `Error while checking for platform warnings: ${ e } ` ) ;
84+ ioHost . defaults . debug ( `Error while checking for platform warnings: ${ e } ` ) ;
8685 }
8786
88- debug ( 'CDK Toolkit CLI version:' , version . displayVersion ( ) ) ;
89- debug ( 'Command line arguments:' , argv ) ;
87+ ioHost . defaults . debug ( 'CDK Toolkit CLI version:' , version . displayVersion ( ) ) ;
88+ ioHost . defaults . debug ( 'Command line arguments:' , argv ) ;
9089
9190 const configuration = new Configuration ( {
9291 commandLineArguments : {
@@ -158,7 +157,7 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise<n
158157 if ( loaded . has ( resolved ) ) {
159158 continue ;
160159 }
161- debug ( `Loading plug-in: ${ chalk . green ( plugin ) } from ${ chalk . blue ( resolved ) } ` ) ;
160+ ioHost . defaults . debug ( `Loading plug-in: ${ chalk . green ( plugin ) } from ${ chalk . blue ( resolved ) } ` ) ;
162161 PluginHost . instance . load ( plugin ) ;
163162 loaded . add ( resolved ) ;
164163 }
@@ -168,8 +167,7 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise<n
168167 try {
169168 return require . resolve ( plugin ) ;
170169 } catch ( e : any ) {
171- error ( `Unable to resolve plugin ${ chalk . green ( plugin ) } : ${ e . stack } ` ) ;
172- throw new ToolkitError ( `Unable to resolve plug-in: ${ plugin } ` ) ;
170+ throw new ToolkitError ( `Unable to resolve plug-in: Cannot find module '${ plugin } '` ) ;
173171 }
174172 }
175173 }
@@ -201,7 +199,7 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise<n
201199 async function main ( command : string , args : any ) : Promise < number | void > {
202200 ioHost . currentAction = command as any ;
203201 const toolkitStackName : string = ToolkitInfo . determineName ( configuration . settings . get ( [ 'toolkitStackName' ] ) ) ;
204- debug ( `Toolkit stack: ${ chalk . bold ( toolkitStackName ) } ` ) ;
202+ ioHost . defaults . debug ( `Toolkit stack: ${ chalk . bold ( toolkitStackName ) } ` ) ;
205203
206204 const cloudFormation = new Deployments ( {
207205 sdkProvider,
@@ -282,7 +280,7 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise<n
282280
283281 case 'bootstrap' :
284282 ioHost . currentAction = 'bootstrap' ;
285- const source : BootstrapSource = determineBootstrapVersion ( args ) ;
283+ const source : BootstrapSource = determineBootstrapVersion ( ioHost , args ) ;
286284
287285 if ( args . showTemplate ) {
288286 const bootstrapper = new Bootstrapper ( source , asIoHelper ( ioHost , ioHost . currentAction ) ) ;
@@ -523,7 +521,7 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise<n
523521 } ) ;
524522 case 'version' :
525523 ioHost . currentAction = 'version' ;
526- return result ( version . displayVersion ( ) ) ;
524+ return ioHost . defaults . result ( version . displayVersion ( ) ) ;
527525
528526 default :
529527 throw new ToolkitError ( 'Unknown command: ' + command ) ;
@@ -534,13 +532,13 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise<n
534532/**
535533 * Determine which version of bootstrapping
536534 */
537- function determineBootstrapVersion ( args : { template ?: string } ) : BootstrapSource {
535+ function determineBootstrapVersion ( ioHost : CliIoHost , args : { template ?: string } ) : BootstrapSource {
538536 let source : BootstrapSource ;
539537 if ( args . template ) {
540- info ( `Using bootstrapping template from ${ args . template } ` ) ;
538+ ioHost . defaults . info ( `Using bootstrapping template from ${ args . template } ` ) ;
541539 source = { source : 'custom' , templateFile : args . template } ;
542540 } else if ( process . env . CDK_LEGACY_BOOTSTRAP ) {
543- info ( 'CDK_LEGACY_BOOTSTRAP set, using legacy-style bootstrapping' ) ;
541+ ioHost . defaults . info ( 'CDK_LEGACY_BOOTSTRAP set, using legacy-style bootstrapping' ) ;
544542 source = { source : 'legacy' } ;
545543 } else {
546544 // in V2, the "new" bootstrapping is the default
@@ -600,13 +598,9 @@ export function cli(args: string[] = process.argv.slice(2)) {
600598 }
601599 } )
602600 . catch ( ( err ) => {
603- error ( err . message ) ;
604-
605601 // Log the stack trace if we're on a developer workstation. Otherwise this will be into a minified
606602 // file and the printed code line and stack trace are huge and useless.
607- if ( err . stack && version . isDeveloperBuild ( ) ) {
608- debug ( err . stack ) ;
609- }
603+ prettyPrintError ( err , version . isDeveloperBuild ( ) ) ;
610604 process . exitCode = 1 ;
611605 } ) ;
612606}
0 commit comments