fs::read_to_string() error handling - non UTF 8 encoded files.
yizakat opened this issue · 3 comments
Firstly, thanks for a great tool. It gets me out of Vivado for my editing for which I'm very grateful!
I'd like to suggest that it would be good to provide more user feedback about the errors that prevent the svlint.toml file being read, I'm assuming that Rust can provide them.
It took me some hours to figure out that on Windows the command "svlint --example > svlint.toml" will produce a UTF16-BOM encoded file (from a powershell session) which cannot be read. That displays the message saying the file cannot be read (which is true) but much of my time was spent trying to figure out why the file path, which is correctly reported, couldn't be accessed which turned out to be a total red herring.
I subsequently tried several different encodings to see what happens, UTF16 files cannot be read, UTF8-BOM files can be read but not parsed.
I'm not game enough to dip my toes into Rust programming yet (although as a C programmer I've very much intending to do so).
@yizakat Thanks for the report - this looks interesting. Can you provide the exact versions of svls/svlint you are using (svlint --version
)? Also, would you zip up your example TOML svlint.toml
and attach it here so we can see exactly what your dealing with?
I have a few suspects:
- ANSI control codes (like for terminal colors) may be getting into the TOML.
- Windows does something different from everything else.
serde
(the Rust crate for (de)serialising the TOML config) may be dependent on your locale https://en.wikipedia.org/wiki/Locale_(computer_software)
FWIW, I often use the standard iconv
utility to check for UTF-8 compliance before reading with svlint. iconv -f UTF-8 -t UTF-8 foo.sv > /dev/null
It's not quite the same as your problem, but may be a useful type of check.
Sure, I'm away from home for the break but will post when I get back.
It is definitely a Windows thing since I don't see the problem at all on Linux. My guess is that it could even be specific to Powershell.
If I explicitly convert the file to UTF8 using Notepad++ it works fine.
Cheers.
@dalance I think this can be closed now. Invalid UTF-8 is handled better in svlint v0.7.0+.