From 781a65ae3251dc2b8a3cc53962295de46828bb31 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Sat, 20 Sep 2025 14:01:01 +0100 Subject: [PATCH] Use appropriate error message in `parseQueriesFromInput` for repo property input --- lib/init-action.js | 22 ++++++++++++++++++++-- src/config/db-config.ts | 15 ++++++++++++++- src/error-messages.ts | 13 +++++++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/lib/init-action.js b/lib/init-action.js index 69082d147..bef956e4a 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -86223,6 +86223,9 @@ function getConfigFileFormatInvalidMessage(configFile) { function getConfigFileDirectoryGivenMessage(configFile) { return `The configuration file "${configFile}" looks like a directory, not a file`; } +function getEmptyCombinesError() { + return `A '+' was used to specify that you want to add extra arguments to the configuration, but no extra arguments were specified. Please either remove the '+' or specify some extra arguments.`; +} function getConfigFilePropertyError(configFile, property, error2) { if (configFile === void 0) { return `The workflow property "${property}" is invalid: ${error2}`; @@ -86230,6 +86233,9 @@ function getConfigFilePropertyError(configFile, property, error2) { return `The configuration file "${configFile}" is invalid: property "${property}" ${error2}`; } } +function getRepoPropertyError(propertyName, error2) { + return `The repository property "${propertyName}" is invalid: ${error2}`; +} function getPacksStrInvalid(packStr, configFile) { return configFile ? getConfigFilePropertyError( configFile, @@ -86398,7 +86404,16 @@ async function calculateAugmentation(rawPacksInput, rawQueriesInput, repositoryP const repoExtraQueriesCombines = shouldCombine(repoExtraQueries); const repoPropertyQueries = { combines: repoExtraQueriesCombines, - input: parseQueriesFromInput(repoExtraQueries, repoExtraQueriesCombines) + input: parseQueriesFromInput( + repoExtraQueries, + repoExtraQueriesCombines, + new ConfigurationError( + getRepoPropertyError( + "github-codeql-extra-queries" /* EXTRA_QUERIES */, + getEmptyCombinesError() + ) + ) + ) }; return { packsInputCombines, @@ -86408,12 +86423,15 @@ async function calculateAugmentation(rawPacksInput, rawQueriesInput, repositoryP repoPropertyQueries }; } -function parseQueriesFromInput(rawQueriesInput, queriesInputCombines) { +function parseQueriesFromInput(rawQueriesInput, queriesInputCombines, errorToThrow) { if (!rawQueriesInput) { return void 0; } const trimmedInput = queriesInputCombines ? rawQueriesInput.trim().slice(1).trim() : rawQueriesInput?.trim() ?? ""; if (queriesInputCombines && trimmedInput.length === 0) { + if (errorToThrow) { + throw errorToThrow; + } throw new ConfigurationError( getConfigFilePropertyError( void 0, diff --git a/src/config/db-config.ts b/src/config/db-config.ts index 00f6eaa0c..501e47a5f 100644 --- a/src/config/db-config.ts +++ b/src/config/db-config.ts @@ -313,7 +313,16 @@ export async function calculateAugmentation( const repoExtraQueriesCombines = shouldCombine(repoExtraQueries); const repoPropertyQueries = { combines: repoExtraQueriesCombines, - input: parseQueriesFromInput(repoExtraQueries, repoExtraQueriesCombines), + input: parseQueriesFromInput( + repoExtraQueries, + repoExtraQueriesCombines, + new ConfigurationError( + errorMessages.getRepoPropertyError( + RepositoryPropertyName.EXTRA_QUERIES, + errorMessages.getEmptyCombinesError(), + ), + ), + ), }; return { @@ -328,6 +337,7 @@ export async function calculateAugmentation( function parseQueriesFromInput( rawQueriesInput: string | undefined, queriesInputCombines: boolean, + errorToThrow?: ConfigurationError, ) { if (!rawQueriesInput) { return undefined; @@ -337,6 +347,9 @@ function parseQueriesFromInput( ? rawQueriesInput.trim().slice(1).trim() : (rawQueriesInput?.trim() ?? ""); if (queriesInputCombines && trimmedInput.length === 0) { + if (errorToThrow) { + throw errorToThrow; + } throw new ConfigurationError( errorMessages.getConfigFilePropertyError( undefined, diff --git a/src/error-messages.ts b/src/error-messages.ts index 61dd3ef92..eb4926677 100644 --- a/src/error-messages.ts +++ b/src/error-messages.ts @@ -1,3 +1,5 @@ +import { RepositoryPropertyName } from "./feature-flags/properties"; + const PACKS_PROPERTY = "packs"; export function getConfigFileOutsideWorkspaceErrorMessage( @@ -29,6 +31,10 @@ export function getConfigFileDirectoryGivenMessage(configFile: string): string { return `The configuration file "${configFile}" looks like a directory, not a file`; } +export function getEmptyCombinesError(): string { + return `A '+' was used to specify that you want to add extra arguments to the configuration, but no extra arguments were specified. Please either remove the '+' or specify some extra arguments.`; +} + export function getConfigFilePropertyError( configFile: string | undefined, property: string, @@ -41,6 +47,13 @@ export function getConfigFilePropertyError( } } +export function getRepoPropertyError( + propertyName: RepositoryPropertyName, + error: string, +): string { + return `The repository property "${propertyName}" is invalid: ${error}`; +} + export function getPacksStrInvalid( packStr: string, configFile?: string,