Skip to content

Commit

Permalink
add try/catch block for when reading imperative.json fails
Browse files Browse the repository at this point in the history
Signed-off-by: Rudy Flores <[email protected]>
  • Loading branch information
rudyflores committed Oct 30, 2023
1 parent 5c4c782 commit 63ee782
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions packages/zowe-explorer/src/utils/ProfilesUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,19 @@ export class ProfilesUtils {
*/
public static getCredentialManagerOverride(): string {
ZoweLogger.trace("ProfilesUtils.getCredentialManagerOverride called.");
const settingsFile = path.join(getZoweDir(), "settings", "imperative.json");
const imperativeConfig = JSON.parse(fs.readFileSync(settingsFile).toString());
const credentialManagerOverride = imperativeConfig?.overrides[imperative.CredentialManagerOverride.CRED_MGR_SETTING_NAME];
if (typeof credentialManagerOverride === "string") {
return credentialManagerOverride;
try {
const settingsFilePath = path.join(getZoweDir(), "settings", "imperative.json");
const settingsFile = fs.readFileSync(settingsFilePath);
const imperativeConfig = JSON.parse(settingsFile.toString());
const credentialManagerOverride = imperativeConfig?.overrides[imperative.CredentialManagerOverride.CRED_MGR_SETTING_NAME];
if (typeof credentialManagerOverride === "string") {
return credentialManagerOverride;
}
return imperative.CredentialManagerOverride.DEFAULT_CRED_MGR_NAME;
} catch (err) {
ZoweLogger.info("imperative.json does not exist, returning the default override of @zowe/cli");
return imperative.CredentialManagerOverride.DEFAULT_CRED_MGR_NAME;

Check warning on line 247 in packages/zowe-explorer/src/utils/ProfilesUtils.ts

View check run for this annotation

Codecov / codecov/patch

packages/zowe-explorer/src/utils/ProfilesUtils.ts#L246-L247

Added lines #L246 - L247 were not covered by tests
}
return imperative.CredentialManagerOverride.DEFAULT_CRED_MGR_NAME;
}

/**
Expand Down

0 comments on commit 63ee782

Please sign in to comment.