Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--help fail on config json error #2301

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
99e5630
all needed changes to meet AC besides tests
ATorrise Oct 9, 2024
6a39c50
changelog and codeql change
ATorrise Oct 9, 2024
1e84a49
still more tests to fix
ATorrise Oct 14, 2024
1d51d5d
i think i put ttests in the right place
ATorrise Oct 22, 2024
150cd03
Merge remote-tracking branch 'origin/master' into error-msg-help-version
ATorrise Oct 22, 2024
d978e0a
linting
ATorrise Oct 24, 2024
a307dd5
removing tests because tests in command processor seem to be enough?
ATorrise Oct 24, 2024
6387262
Update packages/imperative/CHANGELOG.md
ATorrise Oct 30, 2024
0b3ebc9
attempting to fix unit test
ATorrise Oct 30, 2024
82fd8f2
removing unneeded snaps
ATorrise Nov 4, 2024
1edf977
adding node 22 support and also removing private config constructor t…
ATorrise Nov 5, 2024
f8f520d
trying to fix my 2 added unit tests for terminal output given flags
ATorrise Nov 5, 2024
6545a33
Merge branch 'master' of https://github.com/zowe/zowe-cli into error-…
zFernand0 Nov 5, 2024
ab791ec
chore: cherry pick d7ea329742879ca1bca05c5fef503b1a57ec09b9
zFernand0 Nov 5, 2024
1b793ac
getting back to normal with changes
ATorrise Nov 5, 2024
128f61b
chore: fix lint warnings
zFernand0 Nov 5, 2024
b459781
update tests
zFernand0 Nov 5, 2024
0d670f7
removing unused vars
ATorrise Nov 5, 2024
db09359
Merge branch 'error-msg-help-version' of https://github.com/zowe/zowe…
ATorrise Nov 5, 2024
2a370f0
addresing timothys batch of suggestions
ATorrise Nov 6, 2024
a2e9282
correcting spy
ATorrise Nov 6, 2024
d332d6c
writing errors
ATorrise Nov 6, 2024
71b032a
Fix config errors not being ignored
t1m0thyj Nov 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/imperative/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
All notable changes to the Imperative package will be documented in this file.

## Recent Changes
- BugFix: Enabling commands with either the `--help` or `--version` flags to still display their information despite any config file issues [#2301](https://github.com/zowe/zowe-cli/pull/2301)
ATorrise marked this conversation as resolved.
Show resolved Hide resolved

- BugFix: Fixed issues flagged by Coverity [#2291](https://github.com/zowe/zowe-cli/pull/2291)

Expand Down
3 changes: 2 additions & 1 deletion packages/imperative/src/config/src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ export class Config {
exists: false,
properties: Config.empty(),
global: layer === Layers.GlobalUser || layer === Layers.GlobalConfig,
user: layer === Layers.ProjectUser || layer === Layers.GlobalUser
user: layer === Layers.ProjectUser || layer === Layers.GlobalUser,
ignoreErrors: process.argv.includes("--help") || process.argv.includes("--version")
ATorrise marked this conversation as resolved.
Show resolved Hide resolved
ATorrise marked this conversation as resolved.
Show resolved Hide resolved
});
}

Expand Down
22 changes: 16 additions & 6 deletions packages/imperative/src/config/src/api/ConfigLayers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import { IConfigLayer } from "../doc/IConfigLayer";
import { ConfigApi } from "./ConfigApi";
import { IConfig } from "../doc/IConfig";
import { TextUtils } from "../../../utilities";
import { CommandResponse } from "../../../cmd/src/response/CommandResponse";

/**
* API Class for manipulating config layers.
Expand All @@ -31,7 +33,7 @@
* @param opts The user and global flags that indicate which of the four
* config files (aka layers) is to be read.
*/
public read(opts?: { user: boolean; global: boolean }) {
public read(opts?: { user: boolean; global: boolean; ignoreErrors: boolean}) {
ATorrise marked this conversation as resolved.
Show resolved Hide resolved
// Attempt to populate the layer
const layer = opts ? this.mConfig.findLayer(opts.user, opts.global) : this.mConfig.layerActive();
if (fs.existsSync(layer.path)) {
Expand All @@ -49,11 +51,19 @@
layer.properties = JSONC.parse(fileContents.toString()) as any;
layer.exists = true;
} catch (e) {
throw new ImperativeError({
msg: `Error parsing JSON in the file '${layer.path}'.\n` +
`Please check this configuration file for errors.\nError details: ${e.message}\nLine ${e.line}, Column ${e.column}`,
suppressDump: true
});
const msg = `Error parsing JSON in the file '${layer.path}'.\n` +
`Please check this configuration file for errors.\nError details: ${e.message}\nLine ${e.line}, Column ${e.column}`;
if (!opts.ignoreErrors){
zFernand0 marked this conversation as resolved.
Show resolved Hide resolved
throw new ImperativeError({
msg:msg,
suppressDump: true
});
} else {
const cmdResp: CommandResponse = new CommandResponse({

Check warning on line 62 in packages/imperative/src/config/src/api/ConfigLayers.ts

View check run for this annotation

Codecov / codecov/patch

packages/imperative/src/config/src/api/ConfigLayers.ts#L61-L62

Added lines #L61 - L62 were not covered by tests
responseFormat: "default"
});
cmdResp.console.log(TextUtils.chalk.red(msg));

Check warning on line 65 in packages/imperative/src/config/src/api/ConfigLayers.ts

View check run for this annotation

Codecov / codecov/patch

packages/imperative/src/config/src/api/ConfigLayers.ts#L65

Added line #L65 was not covered by tests
ATorrise marked this conversation as resolved.
Show resolved Hide resolved
}
}
this.mConfig.api.secure.loadCached(opts);
} else if (layer.exists) {
Expand Down
1 change: 1 addition & 0 deletions packages/imperative/src/config/src/doc/IConfigLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export interface IConfigLayer {
properties: IConfig;
global: boolean;
user: boolean;
ignoreErrors: boolean;
ATorrise marked this conversation as resolved.
Show resolved Hide resolved
}
Loading