Skip to content

Commit 3a28cb4

Browse files
Merge pull request #131 from github/languages_error
Improve error messages when no languages or no queries are specified
2 parents 42235cc + 44c88fd commit 3a28cb4

File tree

6 files changed

+54
-16
lines changed

6 files changed

+54
-16
lines changed

lib/config-utils.js

Lines changed: 17 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/config-utils.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/config-utils.test.js

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/config-utils.test.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config-utils.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,9 @@ test("default queries are used", async t => {
224224
resolveQueriesArgs.push({queries, extraSearchPath});
225225
return {
226226
byLanguage: {
227-
'javascript': {},
227+
'javascript': {
228+
'foo.ql': {},
229+
},
228230
},
229231
noDeclaredLanguage: {},
230232
multipleDeclaredLanguages: {},
@@ -262,7 +264,11 @@ test("API client used when reading remote config", async t => {
262264
CodeQL.setCodeQL({
263265
resolveQueries: async function() {
264266
return {
265-
byLanguage: {},
267+
byLanguage: {
268+
'javascript': {
269+
'foo.ql': {},
270+
},
271+
},
266272
noDeclaredLanguage: {},
267273
multipleDeclaredLanguages: {},
268274
};

src/config-utils.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,9 @@ async function getLanguagesInRepo(): Promise<string[]> {
452452
* The result is obtained from the action input parameter 'languages' if that
453453
* has been set, otherwise it is deduced as all languages in the repo that
454454
* can be analysed.
455+
*
456+
* If no languages could be detected from either the workflow or the repository
457+
* then throw an error.
455458
*/
456459
async function getLanguages(): Promise<string[]> {
457460

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

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

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

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

524529
const queries = {};
525530
const pathsIgnore: string[] = [];
@@ -572,6 +577,15 @@ async function loadConfig(configFile: string): Promise<Config> {
572577
});
573578
}
574579

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

0 commit comments

Comments
 (0)