diff options
author | jade <lix@jade.fyi> | 2024-09-26 17:07:29 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@localhost> | 2024-09-26 17:07:29 +0000 |
commit | 5dc7671d81845cc9832752209daa591b401ae0c9 (patch) | |
tree | 454fe20cf4184c5c0739f58c5b7a76a6dc7aa95b /src/libutil | |
parent | b6038e988d989f3306e1c7cce8796a685cd8b0d0 (diff) | |
parent | aca19187d0f247de09e79c5c223f88ae82e44b45 (diff) |
Merge "fmt: fail hard on bad format strings going into nix::fmt too" into main
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/fmt.hh | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/libutil/fmt.hh b/src/libutil/fmt.hh index ee3e1e2e7..5feefdf90 100644 --- a/src/libutil/fmt.hh +++ b/src/libutil/fmt.hh @@ -136,11 +136,17 @@ inline std::string fmt(const char * s) template<typename... Args> inline std::string fmt(const std::string & fs, const Args &... args) -{ +try { boost::format f(fs); fmt_internal::setExceptions(f); (f % ... % args); return f.str(); +} catch (boost::io::format_error & fe) { + // I don't care who catches this, we do not put up with boost format errors + // Give me a stack trace and a core dump + std::cerr << "nix::fmt threw format error. Original format string: '"; + std::cerr << fs << "'; number of arguments: " << sizeof...(args) << "\n"; + std::terminate(); } /** @@ -174,15 +180,13 @@ public: std::cerr << "HintFmt received incorrect number of format args. Original format string: '"; std::cerr << format << "'; number of arguments: " << sizeof...(args) << "\n"; // And regardless of the coredump give me a damn stacktrace. - printStackTrace(); - abort(); + std::terminate(); } } catch (boost::io::format_error & ex) { // Same thing, but for anything that happens in the member initializers. std::cerr << "HintFmt received incorrect format string. Original format string: '"; std::cerr << format << "'; number of arguments: " << sizeof...(args) << "\n"; - printStackTrace(); - abort(); + std::terminate(); } HintFmt(const HintFmt & hf) : fmt(hf.fmt) {} |