Skip to content

Fix encoding fallback error handling and error message formatting#9205

Merged
headius merged 1 commit intojruby:masterfrom
khasinski:fix-encoding-fallback-errors
Feb 2, 2026
Merged

Fix encoding fallback error handling and error message formatting#9205
headius merged 1 commit intojruby:masterfrom
khasinski:fix-encoding-fallback-errors

Conversation

@khasinski
Copy link
Contributor

Summary

Follow-up to #9182 as suggested by @headius.

This PR fixes the remaining 12 failing specs in spec/ruby/core/string/encode_spec.rb:

  1. Raise ArgumentError("too big fallback string") when a fallback function returns a value that cannot be encoded to the destination encoding. Previously, the invalid character was silently dropped.

  2. Format UTF-8 codepoints as U+XXXX in UndefinedConversionError messages instead of showing the raw byte dump (e.g., U+FFFD instead of "\xEF\xBF\xBD"), matching MRI behavior.

Test plan

  • All 152 specs in encode_spec.rb now pass (previously 12 were tagged as failing)
  • Removed spec/tags/ruby/core/string/encode_tags.txt since all specs now pass

- Raise ArgumentError("too big fallback string") when a fallback
  function returns a value that cannot be encoded to the destination
  encoding. Previously, the invalid character was silently dropped.

- Format UTF-8 codepoints as U+XXXX in UndefinedConversionError messages
  instead of showing the raw byte dump (e.g., "U+FFFD" instead of
  "\xEF\xBF\xBD"), matching MRI behavior.

These changes fix all 12 failing specs in encode_spec.rb related to
fallback option error handling.
@headius
Copy link
Member

headius commented Feb 2, 2026

Nice! I'll review.

Copy link
Member

@headius headius left a comment

Choose a reason for hiding this comment

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

Love seeing those tags disappear!

@headius headius merged commit 5a70d99 into jruby:master Feb 2, 2026
77 checks passed
@headius headius added this to the JRuby 10.0.3.0 milestone Feb 2, 2026
@khasinski khasinski deleted the fix-encoding-fallback-errors branch February 2, 2026 16:20
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