Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle error encoding string without failing the occurrence #942

Merged
merged 1 commit into from
Feb 21, 2020

Conversation

waltjones
Copy link
Contributor

Specific strings in an occurrence may contain encodings that cannot map to UTF-8. For example, the Vietnamese encoding Windows-1258 allows sequences that have no valid mapping in UTF-8.

When a mapping fails, it is better to provide a diagnostic error for the specific string than to fail the occurrence. Failsafe error occurrences don't show where the failed string mapping happened, and don't provide useful information about the original error. Preserving and sending the original error is an improvement on both points.

@waltjones waltjones merged commit b3dcbb4 into master Feb 21, 2020
@@ -30,6 +30,9 @@ def encode
end

object.is_a?(Symbol) ? encoded_value.to_sym : encoded_value
rescue StandardError => e
# If encoding fails for any reason, replace the string with a diagnostic error.
"error encoding string: #{e.class}: #{e.message}"
Copy link
Contributor

Choose a reason for hiding this comment

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

I have a really robust solution in the EncodedString gem which I extracted from some work in rspec ¯\_(ツ)_/¯

use it as a reference or rely on it. Either way.

@waltjones waltjones deleted the wj-handle-encoding-errors branch June 27, 2023 18:11
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