-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
msvc_sink throws on invalid utf-8 #3241
Comments
Loggers never throw. The sinks might throw but loggers catch everything, so I am not sure what is the problem |
Ah OK. Then please disregard my comments on safety. What do you think about just logging the text that's a bit garbled in this case instead of throwing? |
I don't think it's a good idea. Might lead to undefined behavior. |
There is no UB involved, The change is safe, the only concern there is about the difference in behavior. The options are:
My opinion is that the latter option is strictly better. What am I missing? |
I agree. PR is welcome. Could you also add a simple test for this ? |
Sure, will do a PR with a test. Thanks! |
This is what
msvc_sink
is doing:Then in
utf8_to_wstrbuf
we have:MB_ERR_INVALID_CHARS
causes the function to fail on invalid characters, and thenutf8_to_wstrbuf
throws.We've run into this when trying to output game data that wasn't utf-8 encoded, had to roll out our own implementation of
msvc_sink
(OpenEnroth/OpenEnroth#1825).My feel here is that logging should work at best effort basis and should not throw unless absolutely necessary (as exception can lead to
std::terminate
). Log calls can be buried somewhere deep in error handling code, and the usual expectation there is that logging calls don't throw.In this particular case writing out text that's a bit garbled is perfectly OK.
The text was updated successfully, but these errors were encountered: