Skip to content

Commit 28dc10a

Browse files
authored
fix(settings): Throw error with explicit message for invalid settings (#31)
1 parent 4aef43b commit 28dc10a

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

src/lib/ggshield-resolver.ts

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ export class GGShieldResolver {
3939
);
4040
return;
4141
} catch (error) {
42+
const errorMessage = error instanceof Error ? error.message : String(error);
4243
this.channel.appendLine(
43-
`Failed to use ggshield version ${this.configuration.ggshieldPath}.`
44+
`${errorMessage}`
4445
);
4546
window.showErrorMessage(
46-
`Failed to use ggshield.`
47+
`${errorMessage}`
4748
);
4849
throw error;
4950
}
@@ -57,30 +58,27 @@ export class GGShieldResolver {
5758
async testConfiguration(
5859
configuration: GGShieldConfiguration
5960
): Promise<void> {
60-
let proc = runGGShieldCommand(configuration, ["--version"]);
61+
let proc = runGGShieldCommand(configuration, ["quota"]);
6162
if (proc.error || proc.stderr.length > 0) {
63+
if (proc.error) {
64+
if (proc.error.message.includes("ENOENT")) {
65+
throw new Error(
66+
`GGShield path provided in settings is invalid: ${configuration.ggshieldPath}.`
67+
);
68+
} else {
69+
throw new Error(proc.error.message);
70+
}
71+
} else if (proc.stderr.includes("Invalid API key")) {
72+
throw new Error(
73+
`API key provided in settings is invalid.`
74+
);
75+
}
6276
throw new Error(
63-
`Configuration provided in settings is invalid: ${proc.error}`
77+
`Configuration provided in settings is invalid: ${proc.stderr}`
6478
);
6579
} else {
6680
this.configuration = configuration;
6781
return;
6882
}
6983
}
70-
71-
/**
72-
* Tries the default bundled version of ggshield.
73-
*
74-
* @returns {Promise<void>} A promise that resolves if the configuration is valid.
75-
*/
76-
private async checkBundledGGShield(): Promise<void> {
77-
let proc = runGGShieldCommand(this.configuration, ["--version"]);
78-
if (proc.error || proc.stderr.length > 0) {
79-
throw new Error(
80-
`ggshield binary not found, architecture not supported: ${proc.error}`
81-
);
82-
} else {
83-
return;
84-
}
85-
}
8684
}

0 commit comments

Comments
 (0)