Skip to content

Explain how to override language autodetection in CodeQL errors - #4335

Open
therealsamyak wants to merge 6 commits into
github:mainfrom
therealsamyak:fix/4334-skip-languages-without-files
Open

therealsamyak wants to merge 6 commits into
github:mainfrom
therealsamyak:fix/4334-skip-languages-without-files

Conversation

@therealsamyak

@therealsamyak therealsamyak commented Nov 19, 2026 •

Copy link
Copy Markdown

Related to #4334.

The GitHub languages API describes the default branch. Automatic language detection can therefore select a language that is absent from the checkout.

When CodeQL reports that it saw no source code, the Action preserves the original error. It adds guidance to set the languages input on init if automatic detection selected a language that is absent. A no-source error can also indicate an extraction or build problem. In CodeQL CLI 2.27.5, an absent JavaScript source and a malformed .xsjs file can produce the same finalization error.

This PR provides troubleshooting guidance for #4334. Automatic skipping requires CodeQL to distinguish missing sources from extraction failures.

Risk assessment

This change affects the text of no-source-code errors. Language selection and analysis behavior remain unchanged.

Which use cases does this change impact?

Code Scanning and Code Quality runs can see the additional guidance on GitHub.com and GitHub Enterprise Server. Advanced setup workflows can use the languages input to select the languages to analyze.

How did/will you validate this change?

  • The exit-code-32 unit test verifies that the Action preserves the original diagnostic and adds the new guidance.
  • npm run build, npm run lint, and npm run test pass.
  • The change-note validator passes.

If something goes wrong after this change is released, what are the mitigation and rollback strategies?

Revert the message change to restore the previous wording.

How will you know if something goes wrong after this change is released?

The guidance appears in the failed workflow's error message. The regression test checks that the error remains a configuration error.

Are there any special considerations for merging or releasing this change?

No changes in other repositories are required for the guidance.

Merge / deployment checklist

  • Existing workflows retain the same language selection and failure behavior.
  • The change note is in unreleased-change-notes/no-source-code-language-guidance.md.
  • The guidance matches the existing troubleshooting documentation.

Language autodetection uses the GitHub languages API. That API reports
the languages of the default branch, and GitHub updates the data in
the background. After the last file of a language is removed, the API
can still report that language. The Action then creates a database for
it, and `analyze` fails with exit code 32 because CodeQL sees no source
code.

When languages are autodetected, check the checkout for files with the
extensions that each extractor declares in its `codeql-extractor.yml`.
Skip a language if no such file exists, and log the reason. Ignore the
JavaScript extractor's `data` file type, because CodeQL does not count
`.json` or `.yml` files as JavaScript source. Languages from the
`languages` input are not changed.

Fixes github#4334
@therealsamyak
therealsamyak requested a review from a team as a code owner November 19, 2026 20:22
Copilot AI adaptive review requested due to automatic review settings November 19, 2026 20:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Autodetection can silently drop languages with build-generated or symlinked sources before tracing begins, leaving code unanalyzed.

3 open issues
What changed in this PR

Addresses #4334 by checking the checkout before selecting autodetected languages, reducing analysis failures caused by stale GitHub language statistics.

Changes:

  • Reads extractor file extensions and filters out autodetected languages without matching files, excluding JavaScript data-file types.
  • Preserves explicit language inputs and languages without declared file types.
  • Adds unit tests, a release note, and regenerated bundled JavaScript.
File Description
unreleased-change-notes/​skip-languages-without-files.md Documents the autodetection behavior change.
src/​languages/​source-files.ts Adds extractor metadata parsing and source-file filtering.
src/​languages/​source-files.test.ts Tests extension parsing, traversal, and filtering.
src/​config-utils.ts Applies source-file filtering to autodetected languages.
src/​config-utils.test.ts Tests autodetection filtering and explicit-input preservation.
lib/​entry-points.js Regenerated bundle containing the TypeScript changes.

Review effort: Balanced (adaptive)

Comment thread src/config-utils.ts Outdated
Comment on lines +293 to +295
if (autodetected) {
languages = filterLanguagesWithSourceFiles(
languages,
Comment thread src/languages/source-files.ts Outdated
): Set<string> {
const found = new Set<string>();
const pendingDirs = [rootDir];
while (pendingDirs.length > 0 && found.size < extensions.size) {
Comment thread src/languages/source-files.ts Outdated
if (entry.name !== ".git") {
pendingDirs.push(path.join(dir, entry.name));
}
} else if (entry.isFile()) {
@jketema

jketema commented Nov 20, 2026

Copy link
Copy Markdown

Hi @therealsamyak,

Although this looks nice in practice, this is not going to work - at least not without further changes - because for a number of the extractors file_types does not accurately reflect which files are being picked up upon. For example, our JavaScript tooling picks up on files with the .xsjs extension, while this extension is not mentioned in JavaScript's codeql-extractor.yml.

The previous fix filtered autodetected languages in init by matching
the extensions in each extractor's codeql-extractor.yml file_types.
That list is not complete. For example, the JavaScript extractor also
extracts .xsjs and .xsjslib files, so a repository with only such files
would lose JavaScript analysis. The pre-build check also missed sources
that the build generates, and it walked the whole checkout.

Use CodeQL's own result instead. When database finalization fails with
the no-source-code-seen error (exit code 32) for an autodetected
language that CodeQL extracts by reading the checkout, analyze now
skips that language with a warning and analyzes the others. Languages
from the languages input and traced languages still fail, because for
them the error usually means a build or configuration problem. If no
autodetected language has source code, analyze still fails.

To support this, init saves whether it autodetected the languages in
the new languagesAutodetected config field, and
wrapCliConfigurationError returns a CliConfigurationError that keeps
the CLI error category.
@jketema

jketema commented Nov 20, 2026 •

Copy link
Copy Markdown

The updated change is also not correct, as CodeQL might not have been able to detect code for other reasons, e.g., a compiler version mismatch. That then is actually an issue with CodeQL that will need to be fixed there.

@therealsamyak therealsamyak changed the title Skip autodetected languages with no source files Skip autodetected languages that CodeQL sees no source code for Nov 20, 2026
Keep CodeQL finalization failures visible. A no-source error can
also indicate a compiler or extractor failure, so it cannot justify
skipping analysis.

Point users to the init languages input when automatic detection
selects a language that is absent from the checkout.
Bring in the latest release mergeback and verify the generated
bundle against the current base.
@therealsamyak therealsamyak changed the title Skip autodetected languages that CodeQL sees no source code for Explain how to override language autodetection in CodeQL errors Nov 20, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants