Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.");
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry if this is a silly question @robertbrignull but will the error appear more prominently (in the Check failure summary, rather than only in the detailed logs) if thrown from here rather than in the calling method as it was before these changes? Or do we also need to change how we throw the error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where the error is thrown from doesn't make a difference to how it is presented.

I'm going to do a test of this to make sure it works and looks presentable before this is merged.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I'd love a link to see what it looks like too!

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