Skip to content

Commit a16caca

Browse files
Fixed PR comments
1 parent df29c86 commit a16caca

File tree

7 files changed

+27
-25
lines changed

7 files changed

+27
-25
lines changed

src/commands/cm/stacks/export-query.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export default class ExportQueryCommand extends Command {
8383
}
8484

8585
this.exportDir = sanitizePath(exportQueryConfig.exportDir);
86+
// Create base context without module name - module field is set dynamically during each module export
8687
exportQueryConfig.context = createLogContext(exportQueryConfig);
8788
log.debug('Export configuration setup completed', exportQueryConfig.context);
8889

src/types/index.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,20 @@ export interface DefaultConfig {
174174
maxCTReferenceDepth: number;
175175
}
176176

177+
/**
178+
* Log context interface for centralized logging
179+
*/
180+
export interface LogContext {
181+
command: string;
182+
module: string;
183+
email: string;
184+
sessionId: string;
185+
apiKey: string;
186+
orgId: string;
187+
authenticationMethod: string;
188+
[key: string]: unknown;
189+
}
190+
177191
export interface QueryExportConfig extends DefaultConfig {
178192
query: string;
179193
skipReferences: boolean;
@@ -189,7 +203,7 @@ export interface QueryExportConfig extends DefaultConfig {
189203
batchDelayMs?: number;
190204
assetBatchSize?: number;
191205
assetBatchDelayMs?: number;
192-
context?: any; // Log context for centralized logging
206+
context?: LogContext; // Log context for centralized logging
193207
}
194208

195209
export interface QueryMetadata {

src/utils/branch-helper.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11

2-
import { getBranchFromAlias, log, formatError, handleAndLogError } from '@contentstack/cli-utilities';
2+
import { getBranchFromAlias, log, handleAndLogError } from '@contentstack/cli-utilities';
33
import { QueryExportConfig } from '../types';
4-
import { createLogContext } from './logger';
54

65
/**
76
* Validates and sets up branch configuration for the stack
@@ -15,7 +14,7 @@ export const setupBranches = async (config: QueryExportConfig, stackAPIClient: a
1514
throw new Error('The branch configuration is invalid.');
1615
}
1716

18-
const context = createLogContext(config);
17+
const context = config.context;
1918

2019
try {
2120
if (config.branchAlias) {
@@ -30,7 +29,7 @@ export const setupBranches = async (config: QueryExportConfig, stackAPIClient: a
3029
.branch(config.branchName)
3130
.fetch()
3231
.catch((err: unknown): any => {
33-
log.error(`Error fetching branch: ${formatError(err)}`, context);
32+
handleAndLogError(err, context, 'Error fetching branch');
3433
return null;
3534
});
3635

@@ -63,7 +62,7 @@ export const setupBranches = async (config: QueryExportConfig, stackAPIClient: a
6362
}
6463
config.branchEnabled = true;
6564
} catch (error) {
66-
handleAndLogError(error, context as any, 'Error setting up branches');
65+
handleAndLogError(error, context, 'Error setting up branches');
6766
throw error;
6867
}
6968
};

src/utils/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export * as fileHelper from './file-helper';
22
export { fsUtil } from './file-helper';
3-
export { log, unlinkFileLogger, createLogContext, LogContext } from './logger';
3+
export { log, unlinkFileLogger, createLogContext } from './logger';
4+
export { LogContext } from '../types';
45
export * from './common-helper';
56
export * from './config-handler';
67
export * from './content-type-helper';

src/utils/logger.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import * as winston from 'winston';
88
import * as path from 'path';
99
import mkdirp from 'mkdirp';
10-
import { QueryExportConfig } from '../types';
10+
import { QueryExportConfig, LogContext } from '../types';
1111
import { sanitizePath, redactObject, configHandler } from '@contentstack/cli-utilities';
1212
const slice = Array.prototype.slice;
1313

@@ -167,19 +167,6 @@ export const unlinkFileLogger = () => {
167167
}
168168
};
169169

170-
/**
171-
* Log context interface for centralized logging
172-
*/
173-
export interface LogContext {
174-
command: string;
175-
module: string;
176-
email: string;
177-
sessionId: string;
178-
apiKey: string;
179-
orgId: string;
180-
authenticationMethod: string;
181-
}
182-
183170
/**
184171
* Creates a context object for logging from QueryExportConfig
185172
*/

src/utils/query-parser.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as fs from 'fs';
2-
import { CLIError, formatError } from '@contentstack/cli-utilities';
2+
import { CLIError, handleAndLogError } from '@contentstack/cli-utilities';
33
import { QueryExportConfig } from '../types';
44

55
export class QueryParser {
@@ -28,15 +28,15 @@ export class QueryParser {
2828
const content = fs.readFileSync(filePath, 'utf-8');
2929
return JSON.parse(content);
3030
} catch (error) {
31-
throw new CLIError(`Failed to parse the query file: ${formatError(error)}`);
31+
handleAndLogError(error, this.config.context, 'Failed to parse the query file');
3232
}
3333
}
3434

3535
private parseFromString(queryString: string): any {
3636
try {
3737
return JSON.parse(queryString);
3838
} catch (error) {
39-
throw new CLIError(`Invalid JSON query: ${formatError(error)}`);
39+
handleAndLogError(error, this.config.context, 'Invalid JSON query');
4040
}
4141
}
4242

src/utils/referenced-asset-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class AssetReferenceHandler {
5151
return result;
5252
} catch (error) {
5353
handleAndLogError(error, this.exportQueryConfig.context, 'Failed to extract assets');
54-
throw error;
54+
return [];
5555
}
5656
}
5757

0 commit comments

Comments
 (0)