Skip to content

fix(mutation): propagate collection errors - #11

Merged
cffls merged 3 commits into
0xPolygon:mainfrom
kriss39:test/mutation-error-propagation
Nov 20, 2026
Merged

cffls merged 3 commits into
0xPolygon:mainfrom
kriss39:test/mutation-error-propagation

Conversation

@kriss39

@kriss39 kriss39 commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Mutation collection currently swallows errors from both annotation scanning and mutant generation. If every changed file hits one of those errors, Analyze sees zero mutants and reports PASS with No mutants generated from changed code.

This change propagates those collection errors instead, preserving the distinction between a genuine zero-mutant result and a failed mutation analysis.

Problem

collectMutants currently handles errors from both collection stages by continuing to the next file:

if err != nil {
    continue
}

If collection fails for all relevant files, the resulting mutant list is empty and Analyze reports the mutation section as passing.

This makes these two states indistinguishable:

  • mutation analysis completed successfully and found no applicable mutants
  • mutation collection failed and therefore produced no mutants

Change

  • Change collectMutants to return ([]Mutant, error).
  • Propagate annotation-scanner errors with the affected file path.
  • Propagate mutant-generator errors with the affected file path.
  • Return collection errors from Analyze.
  • Add regression coverage for both scanner and generator failures.

Tests

The regression test injects deterministic failures through a fake lang.Language implementation and verifies that Analyze returns an error wrapping the original cause.

Before the fix, these cases are silently converted into a successful zero-mutant result.

After the fix, the original errors are propagated.

Design note

This PR uses fail-fast propagation because reporting PASS loses the distinction between "no applicable mutants" and "mutation collection failed."

If partial-results or warning behavior is preferred for individual file failures, I am happy to adjust the reporting policy while preserving that distinction.

@kriss39

kriss39 commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

@cffls would you have a moment to look at this one when you can? Collection errors from the mutation step were dropped instead of returned, so a failed collection looked like a clean run. The change propagates them and adds a test. It is mergeable against main as of today (after #12), and I can rebase it if you prefer.

@cffls cffls left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: internal/mutation/mutation_test.go is gofmt-clean on main but not on this branch. The fields in the test table struct (scannerErr / generatorErr) and the one-line methods on analysisErrorLanguage need realigning. Could you run gofmt -w internal/mutation/mutation_test.go (or gofumpt)? CI has no gofmt gate, so it won't flag this.

@kriss39

kriss39 commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, ran gofmt -w on it in 05c9e32. Both files touched by this PR are gofmt-clean now.

@cffls

cffls commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

@kriss39 could you please sign your commits? The PR could only be merged with signed commits.

@kriss39
kriss39 force-pushed the test/mutation-error-propagation branch from 05c9e32 to 5f98126 Compare November 20, 2026 19:50
@kriss39

kriss39 commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Signed now, all three commits show as verified. Contents are unchanged, and the gofmt fix is already in the last commit.

@cffls
cffls merged commit c7992cf into 0xPolygon:main Nov 20, 2026
2 checks passed
@cffls

cffls commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

Thanks @kriss39 ! The PR is merged.

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.

2 participants