@@ -3,13 +3,14 @@ import {
33 flags ,
44 FlagInput ,
55 sanitizePath ,
6- formatError ,
76 managementSDKClient ,
87 ContentstackClient ,
8+ log ,
9+ handleAndLogError ,
910} from '@contentstack/cli-utilities' ;
1011import { QueryExporter } from '../../../core/query-executor' ;
1112import { QueryExportConfig } from '../../../types' ;
12- import { log , setupQueryExportConfig , setupBranches } from '../../../utils' ;
13+ import { setupQueryExportConfig , setupBranches , createLogContext } from '../../../utils' ;
1314
1415export default class ExportQueryCommand extends Command {
1516 static description = 'Export content from a stack using query-based filtering' ;
@@ -82,6 +83,9 @@ export default class ExportQueryCommand extends Command {
8283 }
8384
8485 this . exportDir = sanitizePath ( exportQueryConfig . exportDir ) ;
86+ // Create base context without module name - module field is set dynamically during each module export
87+ exportQueryConfig . context = createLogContext ( exportQueryConfig ) ;
88+ log . debug ( 'Export configuration setup completed' , exportQueryConfig . context ) ;
8589
8690 // Initialize management API client
8791 const managementAPIClient : ContentstackClient = await managementSDKClient ( exportQueryConfig ) ;
@@ -94,16 +98,18 @@ export default class ExportQueryCommand extends Command {
9498
9599 // Setup branches (validate branch or set default to 'main')
96100 await setupBranches ( exportQueryConfig , stackAPIClient ) ;
101+ log . debug ( 'Branch configuration setup completed' , exportQueryConfig . context ) ;
97102
98103 // Initialize and run query export
104+ log . debug ( 'Starting query exporter' , exportQueryConfig . context ) ;
99105 const queryExporter = new QueryExporter ( managementAPIClient , exportQueryConfig ) ;
100106 await queryExporter . execute ( ) ;
107+ log . debug ( 'Query exporter completed successfully' , exportQueryConfig . context ) ;
101108
102- log ( exportQueryConfig , 'Query-based export completed successfully!' , 'success' ) ;
103- log ( exportQueryConfig , `Export files saved to: ${ this . exportDir } ` , 'info' ) ;
109+ log . success ( 'Query-based export completed successfully!' , exportQueryConfig . context ) ;
110+ log . info ( `Export files saved to: ${ this . exportDir } ` , exportQueryConfig . context ) ;
104111 } catch ( error ) {
105- log ( { exportDir : this . exportDir } as QueryExportConfig , `Export failed: ${ formatError ( error ) } ` , 'error' ) ;
106- throw error ;
112+ handleAndLogError ( error ) ;
107113 }
108114 }
109115}
0 commit comments