Skip to content

Commit 91ef965

Browse files
authored
Merge pull request #2040 from contentstack/fix/backupdir-undefined-issue
Fix: Handle undefined backup directory in import plugin when module throws an error
2 parents 0a84a62 + d76f4d9 commit 91ef965

File tree

5 files changed

+29
-22
lines changed

5 files changed

+29
-22
lines changed

.talismanrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fileignoreconfig:
8080
- filename: packages/contentstack-export/src/commands/cm/stacks/export.ts
8181
checksum: ece7891cb6fd7edff4a3cd54adb03ba8f7d8d5758f52d98a5c0ff0bd1b071f74
8282
- filename: packages/contentstack-import/src/commands/cm/stacks/import.ts
83-
checksum: c979bcc18cb0d3e5c58f1b27a106b3d89bb6524d47c0cc2b2fd199031ea33279
83+
checksum: 97463e90433387396c1effeef8eed736179b85e3674398fc7ad22c936f7d8393
8484
- filename: packages/contentstack-export/src/export/modules/custom-roles.ts
8585
checksum: 4fc0f5cab039c84d1a12cdae90dcdcaf15ba461b23007635dc997aada75bbb23
8686
- filename: packages/contentstack-import/src/utils/extension-helper.ts

packages/contentstack-config/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-config
1818
$ csdx COMMAND
1919
running command...
2020
$ csdx (--version)
21-
@contentstack/cli-config/1.14.0 darwin-arm64 node-v22.14.0
21+
@contentstack/cli-config/1.15.0 darwin-arm64 node-v22.14.0
2222
$ csdx --help [COMMAND]
2323
USAGE
2424
$ csdx COMMAND

packages/contentstack-import/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ $ npm install -g @contentstack/cli-cm-import
4747
$ csdx COMMAND
4848
running command...
4949
$ csdx (--version)
50-
@contentstack/cli-cm-import/1.26.0 darwin-arm64 node-v22.14.0
50+
@contentstack/cli-cm-import/1.26.1 darwin-arm64 node-v22.14.0
5151
$ csdx --help [COMMAND]
5252
USAGE
5353
$ csdx COMMAND

packages/contentstack-import/src/commands/cm/stacks/import.ts

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515

1616
import { Context, ImportConfig } from '../../../types';
1717
import { ModuleImporter } from '../../../import';
18-
import { setupImportConfig } from '../../../utils';
18+
import { setupImportConfig } from '../../../utils';
1919

2020
export default class ImportCommand extends Command {
2121
static description = messageHandler.parse('Import content from a stack');
@@ -149,53 +149,60 @@ export default class ImportCommand extends Command {
149149
let importConfig: ImportConfig = await setupImportConfig(flags);
150150
// Prepare the context object
151151
const context = this.createImportContext(importConfig.apiKey, importConfig.authenticationMethod);
152-
importConfig.context = {...context};
152+
importConfig.context = { ...context };
153153
//log.info(`Using Cli Version: ${this.context?.cliVersion}`, importConfig.context);
154-
154+
155155
// Note setting host to create cma client
156156
importConfig.host = this.cmaHost;
157157
importConfig.region = this.region;
158158
if (this.developerHubUrl) importConfig.developerHubBaseUrl = this.developerHubUrl;
159159
if (this.personalizeUrl) importConfig.modules.personalize.baseURL[importConfig.region.name] = this.personalizeUrl;
160-
160+
161161
const managementAPIClient: ContentstackClient = await managementSDKClient(importConfig);
162-
162+
163163
if (!flags.branch) {
164164
try {
165165
// Use stack configuration to check for branch availability
166166
// false positive - no hardcoded secret here
167-
// @ts-ignore-next-line secret-detection
167+
// @ts-ignore-next-line secret-detection
168168
const keyProp = 'api_key';
169169
const branches = await managementAPIClient
170-
.stack({ [keyProp]: importConfig.apiKey })
171-
.branch()
172-
.query()
173-
.find()
174-
.then(({ items }: any) => items);
170+
.stack({ [keyProp]: importConfig.apiKey })
171+
.branch()
172+
.query()
173+
.find()
174+
.then(({ items }: any) => items);
175175
if (branches.length) {
176176
flags.branch = 'main';
177177
}
178178
} catch (error) {
179179
// Branch not enabled, just the let flow continue
180180
}
181181
}
182+
183+
// Set backupDir early so it's available in error handling
184+
backupDir = importConfig.backupDir;
185+
182186
const moduleImporter = new ModuleImporter(managementAPIClient, importConfig);
183187
const result = await moduleImporter.start();
184-
backupDir = importConfig.backupDir;
185188

186-
if (!result?.noSuccessMsg) {
189+
if (!result?.noSuccessMsg) {
187190
const successMessage = importConfig.stackName
188-
? `Successfully imported the content to the stack named ${importConfig.stackName} with the API key ${importConfig.apiKey} .`
189-
: `The content has been imported to the stack ${importConfig.apiKey} successfully!`;
191+
? `Successfully imported the content to the stack named ${importConfig.stackName} with the API key ${importConfig.apiKey} .`
192+
: `The content has been imported to the stack ${importConfig.apiKey} successfully!`;
190193
log.success(successMessage, importConfig.context);
191194
}
192195

193-
log.success(`The log has been stored at '${getLogPath()}'`, importConfig.context)
196+
log.success(`The log has been stored at '${getLogPath()}'`, importConfig.context);
194197
log.info(`The backup content has been stored at '${backupDir}'`, importConfig.context);
195198
} catch (error) {
196199
handleAndLogError(error);
197-
log.info(`The log has been stored at '${getLogPath()}'`)
198-
log.info(`The backup content has been stored at '${backupDir}'`);
200+
log.info(`The log has been stored at '${getLogPath()}'`);
201+
if (backupDir) {
202+
log.info(`The backup content has been stored at '${backupDir}'`);
203+
} else {
204+
log.info('No backup directory was created due to early termination');
205+
}
199206
}
200207
}
201208

packages/contentstack/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli
1818
$ csdx COMMAND
1919
running command...
2020
$ csdx (--version|-v)
21-
@contentstack/cli/1.44.0 darwin-arm64 node-v22.14.0
21+
@contentstack/cli/1.44.1 darwin-arm64 node-v22.14.0
2222
$ csdx --help [COMMAND]
2323
USAGE
2424
$ csdx COMMAND

0 commit comments

Comments
 (0)