-
Notifications
You must be signed in to change notification settings - Fork 38.8k
util: Make strprintf noexcept. Improve error message on format string error. #13392
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
Conversation
877a8ee to
0e64579
Compare
0e64579 to
98b0198
Compare
|
Mild NACK I prefer noisy failures. If the failures here are burdensome, can you cite some? |
|
@Empact How is this less noisy than before? :-) - format(oss, fmt.c_str(), args...);
+ try {
+ tfm::format(oss, fmt.c_str(), args...);
+ } catch (const tinyformat::format_error& fmterr) {
+ fprintf(stderr, "Format error: %s (fmt=\"%s\")\n", fmterr.what(), fmt.c_str());
+ std::terminate();
+ } |
|
Basically, blow up when possible, return a value or log or both when not possible. Make errors as difficult to ignore as possible. |
|
@Empact I agree, but I don't get how this is less noisy. |
|
Fair enough, terminate is effectively noisy, but given terminate would be called if the exception were uncaught, ironically, this now makes errors which would have previously been blanket-caught via FTR I don't like that we have blanket-catches in the codebase, but they're sometimes warranted. |
|
Hopefully we will have format string linting soon (see separate PR) and perhaps that will allow us to make |
| The last travis run for this pull request was 54 days ago and is thus outdated. To trigger a fresh travis build, this pull request should be closed and re-opened. |
Note to reviewers: This pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
|
I'm going to close this, I don't think this change is really necessary. |
Make
strprintfnoexcept. Improve the error message given on format string errors.With this change large parts of the code base (
strprintfcallers directly or indirectly) are switched from an implicit "might throwtinyformat::format_error" to "will not throw" from a compiler/static analyzer perspective.Also, reducing the number of unnecessary exceptions thrown increases the signal-to-noise for humans when analyzing potential issues introduced by uncaught exceptions.
These were the conditions that could make
strprintf(…)throwtinyformat::format_errorprior to this commit: