Skip to content

Don't crash on references without a line number when purging - #460

Merged
whatyouhide merged 1 commit into
elixir-gettext:mainfrom
oliver-kriska:purge-ref-without-line
Dec 4, 2026
Merged

whatyouhide merged 1 commit into
elixir-gettext:mainfrom
oliver-kriska:purge-ref-without-line

Conversation

@oliver-kriska

Copy link
Copy Markdown
Contributor
  • With :excluded_refs_from_purging set, mix gettext.extract raises a FunctionClauseError when an existing POT message that is no longer extracted has a reference without a line number.
  • Gettext writes such references itself with write_reference_line_numbers: false, and other tools write them too (#: web/static/js/app.js).
  • protected?/2 now accepts both reference shapes, the same way the merger already does.

For a POT message that is no longer extracted, with excluded_refs_from_purging: ~r{^web/static/}:

Reference Before After
#: web/static/js/app.js:10 kept kept
#: web/static/js/app.js FunctionClauseError kept
#: lib/foo.ex FunctionClauseError removed if autogenerated, as with a line number

The error on main:

** (FunctionClauseError) no function clause matching in anonymous fn/1 in Gettext.Extractor.protected?/2
    lib/gettext/extractor.ex:617: anonymous fn/1 in Gettext.Extractor.protected?/2

Checks

  • Two new tests in extractor_test.exs, next to "allowed messages are kept": line-less and mixed references that match (kept), and ones that do not match (removed). Both fail on main with the error above.
  • Also reproduced from a POT file on disk through Gettext.Extractor.merge_pot_files/3: it crashes on main and works with the fix.
  • mix format --check-formatted, mix compile --warnings-as-errors and mix test pass (196 passed).

🤖 Generated with Claude Code

With :excluded_refs_from_purging set, merging an existing POT file
raised a FunctionClauseError when a message that was no longer
extracted had a reference without a line number, such as the ones
written with write_reference_line_numbers: false.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@whatyouhide

Copy link
Copy Markdown
Contributor

Thank you Claude and @oliver-kriska.

@whatyouhide
whatyouhide merged commit ba95686 into elixir-gettext:main Dec 4, 2026
2 checks passed
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