@@ -3,10 +3,10 @@ import {
33 flags ,
44 FlagInput ,
55 sanitizePath ,
6- formatError ,
76 managementSDKClient ,
87 ContentstackClient ,
98 log ,
9+ handleAndLogError ,
1010} from '@contentstack/cli-utilities' ;
1111import { QueryExporter } from '../../../core/query-executor' ;
1212import { QueryExportConfig } from '../../../types' ;
@@ -83,8 +83,8 @@ export default class ExportQueryCommand extends Command {
8383 }
8484
8585 this . exportDir = sanitizePath ( exportQueryConfig . exportDir ) ;
86- const context = createLogContext ( exportQueryConfig ) ;
87- log . debug ( 'Export configuration setup completed' , context ) ;
86+ exportQueryConfig . context = createLogContext ( exportQueryConfig ) ;
87+ log . debug ( 'Export configuration setup completed' , exportQueryConfig . context ) ;
8888
8989 // Initialize management API client
9090 const managementAPIClient : ContentstackClient = await managementSDKClient ( exportQueryConfig ) ;
@@ -97,21 +97,18 @@ export default class ExportQueryCommand extends Command {
9797
9898 // Setup branches (validate branch or set default to 'main')
9999 await setupBranches ( exportQueryConfig , stackAPIClient ) ;
100- log . debug ( 'Branch configuration setup completed' , context ) ;
100+ log . debug ( 'Branch configuration setup completed' , exportQueryConfig . context ) ;
101101
102102 // Initialize and run query export
103- log . debug ( 'Starting query exporter' , context ) ;
103+ log . debug ( 'Starting query exporter' , exportQueryConfig . context ) ;
104104 const queryExporter = new QueryExporter ( managementAPIClient , exportQueryConfig ) ;
105105 await queryExporter . execute ( ) ;
106- log . debug ( 'Query exporter completed successfully' , context ) ;
106+ log . debug ( 'Query exporter completed successfully' , exportQueryConfig . context ) ;
107107
108- log . success ( 'Query-based export completed successfully!' , context ) ;
109- log . info ( `Export files saved to: ${ this . exportDir } ` , context ) ;
108+ log . success ( 'Query-based export completed successfully!' , exportQueryConfig . context ) ;
109+ log . info ( `Export files saved to: ${ this . exportDir } ` , exportQueryConfig . context ) ;
110110 } catch ( error ) {
111- const errorConfig = { exportDir : this . exportDir , stackApiKey : '' } as QueryExportConfig ;
112- const errorContext = createLogContext ( errorConfig ) ;
113- log . error ( `Export failed: ${ formatError ( error ) } ` , errorContext ) ;
114- throw error ;
111+ handleAndLogError ( error ) ;
115112 }
116113 }
117114}
0 commit comments