set explicit encoding when reading and writing hex config #2405
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
(fixes erlef/rebar3_hex#184)
The issue was that the bytes were written "as is" on disk, while Erlang source files are expected to be utf8 (and no longer latin1) by default since Erlang/OTP 17.0 (as per https://erlang.org/doc/reference_manual/character_set.html)
e.g. byte <<200>> (0xC8) is not valid utf8, but was written as is, causing
file:consult
to raise an encoding error.It is preferable not to rely on default behavior, and specify an encoding both at write and read time.
This PR specifies utf8 (probably more future-proof than latin1) when calling
file:write_file
and adds the encoding at the top of the file for future reads viafile:consult
(as per https://erlang.org/doc/reference_manual/character_set.html#source-file-encoding).The test writes to the actual config at the moment. How should I stub it out, knowing that it should still use
file:file_write
andfile:consult
and have the same semantics? Maybe an in-memory file, etccc @starbelly @ferd