Make error message tests less brittle

This commit is contained in:
Michael B. Gale
2025-10-29 08:29:11 +00:00
parent 53acf0b8aa
commit 194ba0ee2d
8 changed files with 34 additions and 10 deletions

View File

@@ -179,7 +179,7 @@ test("wrapApiConfigurationError correctly wraps specific configuration errors",
t.deepEqual(
res,
new util.ConfigurationError(
`Please verify that the necessary features are enabled: ${codeSecurityNotEnabledError.message}`,
api.getFeatureEnablementError(codeSecurityNotEnabledError.message),
),
);
const advancedSecurityNotEnabledError = new util.HTTPError(
@@ -190,7 +190,7 @@ test("wrapApiConfigurationError correctly wraps specific configuration errors",
t.deepEqual(
res,
new util.ConfigurationError(
`Please verify that the necessary features are enabled: ${advancedSecurityNotEnabledError.message}`,
api.getFeatureEnablementError(advancedSecurityNotEnabledError.message),
),
);
const codeScanningNotEnabledError = new util.HTTPError(
@@ -201,7 +201,7 @@ test("wrapApiConfigurationError correctly wraps specific configuration errors",
t.deepEqual(
res,
new util.ConfigurationError(
`Please verify that the necessary features are enabled: ${codeScanningNotEnabledError.message}`,
api.getFeatureEnablementError(codeScanningNotEnabledError.message),
),
);
});

View File

@@ -291,6 +291,12 @@ function isEnablementError(msg: string) {
].some((pattern) => pattern.test(msg));
}
// TODO: Move to `error-messages.ts` after refactoring import order to avoid cycle
// since `error-messages.ts` currently depends on this file.
export function getFeatureEnablementError(message: string): string {
return `Please verify that the necessary features are enabled: ${message}`;
}
export function wrapApiConfigurationError(e: unknown) {
const httpError = asHTTPError(e);
if (httpError !== undefined) {
@@ -314,7 +320,7 @@ export function wrapApiConfigurationError(e: unknown) {
}
if (isEnablementError(httpError.message)) {
return new ConfigurationError(
`Please verify that the necessary features are enabled: ${httpError.message}`,
getFeatureEnablementError(httpError.message),
);
}
if (httpError.status === 429) {