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
Avoid fmt
when constructor already does it
#3720
Conversation
There are a few similar cases in:
(most of those won't have a percent though, but best to be safe) |
This is a regression compared to 2.3, where both /* A helper for formatting strings. ‘fmt(format, a_0, ..., a_n)’ is
equivalent to ‘boost::format(format) % a_0 % ... %
... a_n’. However, ‘fmt(s)’ is equivalent to ‘s’ (so no %-expansion
takes place). */
inline std::string fmt(const std::string & s)
{
return s;
}
... We should restore that specialisation. |
#3724 is better to fix the underlying issue, so I'll make this just a duplicate formatting cleanup. |
fmt
for tidyness
fmt
for tidynessfmt
for tidiness
639e20d
to
de1ec0f
Compare
fmt
for tidinessfmt
when constructor already does it
fmt
when constructor already does itfmt
when constructor already does it
Guess |
Huh, this is the second PR of mine where there are weird perl issues. |
What do the SQLite changes do? |
@edolstra they shouldn't have any observable effect. The idea is the helper function takes var args like the error constructors, formatiting the users format string. Also, the errors themselves store the original information (error number and extended error number) should somebody want to display the information differently. With @bburdette's approval, I would complete the process of separating structure and presentation by making |
I marked this as stale due to inactivity. → More info |
I closed this issue due to inactivity. → More info |
de1ec0f
to
0081b75
Compare
I think this is till a good cleanup. Rebased it. |
There is a correctnes issue here, but NixOS#3724 will fix that. This is just a cleanup for brevity's sake.
0081b75
to
75b62e5
Compare
fmt
when constructor already does itfmt
when constructor already does it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is till a good cleanup
Indeed, thanks for the rebase :)
There’s just an issue with the sqlite stuff where you introduce a nasty little footgun. Other than that 👍
src/libstore/sqlite.hh
Outdated
int errNo, extendedErrNo; | ||
|
||
template<typename... Args> | ||
[[noreturn]] static void throw_(sqlite3 * db, const std::string & fs, const Args & ... args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless I’m missing something, this is very fragile since the definition of the templated function isn’t in the header − so only the instances of the template that happen to be used in sqlite.cc
will be available outside (which happens to be the case because the only usages outside of sqlite.cc
seem to be whith args
being a single string)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh good catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed it an even better way!
This ensures that use-sites properly trigger new monomorphisations on one hand, and on the other hand keeps the main `sqlite.hh` clean and interface-only. I think that is good practice in general, but in this situation in particular we do indeed have `sqlite.hh` users that don't need the `throw_` function.
The templating is very superficial
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good now :)
Set to merge once the CI is green ✔️
I wonder if this may have broken the build (run link:
|
It did indeed :/ Looking at it right now |
Thanks for fixing! |
We have a larger problem that passing computed strings to the firstvariable argument of many exception constructors is unsafe because that
first variable argument is interpreted not as a plain string, but format
string, and if it contains '%' boost::format will abort, since there are
no arguments to the format string.
In this particular instance '%' was used as part of an escape code in a
URL, which, when the download failed, caused Nix to abort displaying the
FileTransferError
.#3724 will fix the underlying issue. This is just a cleanup for brevity's sake.
Most of the changes are very straight forward, but I did refactor a bit more aggressively with the SQLite errors, taking
SysError
my guide.CC @bburdette