More readable error message for invalid queries block
When someone creates an invalid `queries` entry in the codeql config
file, like this:
```
queries:
- foo.ql
```
THe error message is confusing, looking like this:
```
Error: Cannot use 'in' operator to search for 'uses' in ql/ql/src
TypeError: Cannot use 'in' operator to search for 'uses' in ql/ql/src
at loadConfig (/home/runner/work/_actions/github/codeql-action/71a8b35ff4c80fcfcd05bc1cd932fe3c08f943ca/lib/config-utils.js:577:41)
```
With this change, the error message is more comprehensible:
`queries must be an array, with each entry having a 'uses' property`
This commit is contained in:
parent
f9bce029b4
commit
fba13b0092
3 changed files with 18 additions and 10 deletions
11
lib/config-utils.js
generated
11
lib/config-utils.js
generated
|
|
@ -19,7 +19,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.getConfig = exports.getPathToParsedConfigFile = exports.initConfig = exports.parsePacks = exports.validatePackSpecification = exports.prettyPrintPack = exports.parsePacksSpecification = exports.parsePacksFromConfig = exports.calculateAugmentation = exports.getDefaultConfig = exports.getUnknownLanguagesError = exports.getNoLanguagesError = exports.getConfigFileDirectoryGivenMessage = exports.getConfigFileFormatInvalidMessage = exports.getConfigFileRepoFormatInvalidMessage = exports.getConfigFileDoesNotExistErrorMessage = exports.getConfigFileOutsideWorkspaceErrorMessage = exports.getLocalPathDoesNotExist = exports.getLocalPathOutsideOfRepository = exports.getPacksStrInvalid = exports.getPacksInvalid = exports.getPacksInvalidSplit = exports.getPathsInvalid = exports.getPathsIgnoreInvalid = exports.getQueryUsesInvalid = exports.getQueriesInvalid = exports.getDisableDefaultQueriesInvalid = exports.getNameInvalid = exports.validateAndSanitisePath = exports.defaultAugmentationProperties = void 0;
|
exports.getConfig = exports.getPathToParsedConfigFile = exports.initConfig = exports.parsePacks = exports.validatePackSpecification = exports.prettyPrintPack = exports.parsePacksSpecification = exports.parsePacksFromConfig = exports.calculateAugmentation = exports.getDefaultConfig = exports.getUnknownLanguagesError = exports.getNoLanguagesError = exports.getConfigFileDirectoryGivenMessage = exports.getConfigFileFormatInvalidMessage = exports.getConfigFileRepoFormatInvalidMessage = exports.getConfigFileDoesNotExistErrorMessage = exports.getConfigFileOutsideWorkspaceErrorMessage = exports.getLocalPathDoesNotExist = exports.getLocalPathOutsideOfRepository = exports.getPacksStrInvalid = exports.getPacksInvalid = exports.getPacksInvalidSplit = exports.getPathsInvalid = exports.getPathsIgnoreInvalid = exports.getQueryUsesInvalid = exports.getQueriesMissingUses = exports.getQueriesInvalid = exports.getDisableDefaultQueriesInvalid = exports.getNameInvalid = exports.validateAndSanitisePath = exports.defaultAugmentationProperties = void 0;
|
||||||
const fs = __importStar(require("fs"));
|
const fs = __importStar(require("fs"));
|
||||||
const path = __importStar(require("path"));
|
const path = __importStar(require("path"));
|
||||||
const yaml = __importStar(require("js-yaml"));
|
const yaml = __importStar(require("js-yaml"));
|
||||||
|
|
@ -303,6 +303,10 @@ function getQueriesInvalid(configFile) {
|
||||||
return getConfigFilePropertyError(configFile, QUERIES_PROPERTY, "must be an array");
|
return getConfigFilePropertyError(configFile, QUERIES_PROPERTY, "must be an array");
|
||||||
}
|
}
|
||||||
exports.getQueriesInvalid = getQueriesInvalid;
|
exports.getQueriesInvalid = getQueriesInvalid;
|
||||||
|
function getQueriesMissingUses(configFile) {
|
||||||
|
return getConfigFilePropertyError(configFile, QUERIES_PROPERTY, "must be an array, with each entry having a 'uses' property");
|
||||||
|
}
|
||||||
|
exports.getQueriesMissingUses = getQueriesMissingUses;
|
||||||
function getQueryUsesInvalid(configFile, queryUses) {
|
function getQueryUsesInvalid(configFile, queryUses) {
|
||||||
return getConfigFilePropertyError(configFile, `${QUERIES_PROPERTY}.${QUERIES_USES_PROPERTY}`, `must be a built-in suite (${builtinSuites.join(" or ")}), a relative path, or be of the form "owner/repo[/path]@ref"${queryUses !== undefined ? `\n Found: ${queryUses}` : ""}`);
|
return getConfigFilePropertyError(configFile, `${QUERIES_PROPERTY}.${QUERIES_USES_PROPERTY}`, `must be a built-in suite (${builtinSuites.join(" or ")}), a relative path, or be of the form "owner/repo[/path]@ref"${queryUses !== undefined ? `\n Found: ${queryUses}` : ""}`);
|
||||||
}
|
}
|
||||||
|
|
@ -574,9 +578,8 @@ async function loadConfig(languagesInput, rawQueriesInput, rawPacksInput, config
|
||||||
throw new Error(getQueriesInvalid(configFile));
|
throw new Error(getQueriesInvalid(configFile));
|
||||||
}
|
}
|
||||||
for (const query of queriesArr) {
|
for (const query of queriesArr) {
|
||||||
if (!(QUERIES_USES_PROPERTY in query) ||
|
if (typeof query[QUERIES_USES_PROPERTY] !== "string") {
|
||||||
typeof query[QUERIES_USES_PROPERTY] !== "string") {
|
throw new Error(getQueriesMissingUses(configFile));
|
||||||
throw new Error(getQueryUsesInvalid(configFile));
|
|
||||||
}
|
}
|
||||||
await parseQueryUses(languages, codeQL, queries, packs, query[QUERIES_USES_PROPERTY], tempDir, workspacePath, apiDetails, featureFlags, logger, configFile);
|
await parseQueryUses(languages, codeQL, queries, packs, query[QUERIES_USES_PROPERTY], tempDir, workspacePath, apiDetails, featureFlags, logger, configFile);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -676,6 +676,14 @@ export function getQueriesInvalid(configFile: string): string {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getQueriesMissingUses(configFile: string): string {
|
||||||
|
return getConfigFilePropertyError(
|
||||||
|
configFile,
|
||||||
|
QUERIES_PROPERTY,
|
||||||
|
"must be an array, with each entry having a 'uses' property"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function getQueryUsesInvalid(
|
export function getQueryUsesInvalid(
|
||||||
configFile: string | undefined,
|
configFile: string | undefined,
|
||||||
queryUses?: string
|
queryUses?: string
|
||||||
|
|
@ -1149,11 +1157,8 @@ async function loadConfig(
|
||||||
throw new Error(getQueriesInvalid(configFile));
|
throw new Error(getQueriesInvalid(configFile));
|
||||||
}
|
}
|
||||||
for (const query of queriesArr) {
|
for (const query of queriesArr) {
|
||||||
if (
|
if (typeof query[QUERIES_USES_PROPERTY] !== "string") {
|
||||||
!(QUERIES_USES_PROPERTY in query) ||
|
throw new Error(getQueriesMissingUses(configFile));
|
||||||
typeof query[QUERIES_USES_PROPERTY] !== "string"
|
|
||||||
) {
|
|
||||||
throw new Error(getQueryUsesInvalid(configFile));
|
|
||||||
}
|
}
|
||||||
await parseQueryUses(
|
await parseQueryUses(
|
||||||
languages,
|
languages,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue