mirror of
https://github.com/github/codeql-action.git
synced 2026-01-06 22:50:17 +08:00
improve error message when config is not found
This commit is contained in:
@@ -32,6 +32,9 @@ async function run() {
|
||||
}
|
||||
const logger = getActionsLogger();
|
||||
const config = await getConfig(util.getRequiredEnvParam('RUNNER_TEMP'), logger);
|
||||
if (config === undefined) {
|
||||
throw new Error("Config file could not be found at expected location. Has the 'init' action been called?");
|
||||
}
|
||||
stats = await runAnalyze(
|
||||
parseRepositoryNwo(util.getRequiredEnvParam('GITHUB_REPOSITORY')),
|
||||
await util.getCommitOid(),
|
||||
|
||||
@@ -45,6 +45,9 @@ async function run() {
|
||||
}
|
||||
|
||||
const config = await config_utils.getConfig(util.getRequiredEnvParam('RUNNER_TEMP'), logger);
|
||||
if (config === undefined) {
|
||||
throw new Error("Config file could not be found at expected location. Has the 'init' action been called?");
|
||||
}
|
||||
language = determineAutobuildLanguage(config, logger);
|
||||
if (language !== undefined) {
|
||||
await runAutobuild(language, config, logger);
|
||||
|
||||
@@ -854,17 +854,13 @@ async function saveConfig(config: Config, logger: Logger) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the config.
|
||||
*
|
||||
* If this is the first time in a workflow that this is being called then
|
||||
* this will parse the config from the user input. The parsed config is then
|
||||
* stored to a known location. On the second and further calls, this will
|
||||
* return the contents of the parsed config from the known location.
|
||||
* Get the config that has been saved to the given temp dir.
|
||||
* If the config could not be found then returns undefined.
|
||||
*/
|
||||
export async function getConfig(tempDir: string, logger: Logger): Promise<Config> {
|
||||
export async function getConfig(tempDir: string, logger: Logger): Promise<Config | undefined> {
|
||||
const configFile = getPathToParsedConfigFile(tempDir);
|
||||
if (!fs.existsSync(configFile)) {
|
||||
throw new Error("Config file could not be found at expected location. Has the 'init' action been called?");
|
||||
return undefined;
|
||||
}
|
||||
const configString = fs.readFileSync(configFile, 'utf8');
|
||||
logger.debug('Loaded config:');
|
||||
|
||||
@@ -188,6 +188,10 @@ program
|
||||
const logger = getRunnerLogger(cmd.debug);
|
||||
try {
|
||||
const config = await getConfig(getTempDir(cmd.tempDir), logger);
|
||||
if (config === undefined) {
|
||||
throw new Error("Config file could not be found at expected location. " +
|
||||
"Was the 'init' command run with the same '--temp-dir' argument as this command.");
|
||||
}
|
||||
checkEnvironmentSetup(config);
|
||||
let language: Language | undefined = undefined;
|
||||
if (cmd.language !== undefined) {
|
||||
@@ -241,6 +245,10 @@ program
|
||||
const tempDir = getTempDir(cmd.tempDir);
|
||||
const outputDir = cmd.outputDir || path.join(tempDir, 'codeql-sarif');
|
||||
const config = await getConfig(getTempDir(cmd.tempDir), logger);
|
||||
if (config === undefined) {
|
||||
throw new Error("Config file could not be found at expected location. " +
|
||||
"Was the 'init' command run with the same '--temp-dir' argument as this command.");
|
||||
}
|
||||
checkEnvironmentSetup(config);
|
||||
await runAnalyze(
|
||||
parseRepositoryNwo(cmd.repository),
|
||||
|
||||
Reference in New Issue
Block a user