Skip to content

Commit

Permalink
Merge pull request #131 from github/languages_error
Browse files Browse the repository at this point in the history
Improve error messages when no languages or no queries are specified
  • Loading branch information
Robert authored and GitHub committed Aug 5, 2020
2 parents 42235cc + 44c88fd commit 3a28cb4
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 16 deletions.
22 changes: 17 additions & 5 deletions lib/config-utils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/config-utils.js.map

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions lib/config-utils.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/config-utils.test.js.map

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions src/config-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ test("default queries are used", async t => {
resolveQueriesArgs.push({queries, extraSearchPath});
return {
byLanguage: {
'javascript': {},
'javascript': {
'foo.ql': {},
},
},
noDeclaredLanguage: {},
multipleDeclaredLanguages: {},
Expand Down Expand Up @@ -262,7 +264,11 @@ test("API client used when reading remote config", async t => {
CodeQL.setCodeQL({
resolveQueries: async function() {
return {
byLanguage: {},
byLanguage: {
'javascript': {
'foo.ql': {},
},
},
noDeclaredLanguage: {},
multipleDeclaredLanguages: {},
};
Expand Down
24 changes: 19 additions & 5 deletions src/config-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,9 @@ async function getLanguagesInRepo(): Promise<string[]> {
* The result is obtained from the action input parameter 'languages' if that
* has been set, otherwise it is deduced as all languages in the repo that
* can be analysed.
*
* If no languages could be detected from either the workflow or the repository
* then throw an error.
*/
async function getLanguages(): Promise<string[]> {

Expand All @@ -468,6 +471,13 @@ async function getLanguages(): Promise<string[]> {
core.info("Automatically detected languages: " + JSON.stringify(languages));
}

// If the languages parameter was not given and no languages were
// detected then fail here as this is a workflow configuration error.
if (languages.length === 0) {
throw new Error("Did not detect any languages to analyze. " +
"Please update input in workflow or check that GitHub detects the correct languages in your repository.");
}

return languages;
}

Expand Down Expand Up @@ -515,11 +525,6 @@ async function loadConfig(configFile: string): Promise<Config> {
}

const languages = await getLanguages();
// If the languages parameter was not given and no languages were
// detected then fail here as this is a workflow configuration error.
if (languages.length === 0) {
throw new Error("Did not detect any languages to analyze. Please update input in workflow.");
}

const queries = {};
const pathsIgnore: string[] = [];
Expand Down Expand Up @@ -572,6 +577,15 @@ async function loadConfig(configFile: string): Promise<Config> {
});
}

// The list of queries should not be empty for any language. If it is then
// it is a user configuration error.
for (const language of languages) {
if (queries[language] === undefined || queries[language].length === 0) {
throw new Error(`Did not detect any queries to run for ${language}. ` +
"Please make sure that the default queries are enabled, or you are specifying queries to run.");
}
}

return {
languages,
queries,
Expand Down

0 comments on commit 3a28cb4

Please sign in to comment.