From: Vsevolod Stakhov Date: Tue, 24 Oct 2023 15:02:59 +0000 (+0100) Subject: [Minor] Improve diagnostics X-Git-Tag: 3.7.2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6b81b812a7a34ad7201b7df214bb543d089d7919;p=thirdparty%2Frspamd.git [Minor] Improve diagnostics --- diff --git a/src/client/rspamc.cxx b/src/client/rspamc.cxx index cf2f9d1dc3..50e3cbdee4 100644 --- a/src/client/rspamc.cxx +++ b/src/client/rspamc.cxx @@ -365,28 +365,36 @@ struct fmt::formatter : fmt::formatter { template static inline void rspamc_print(std::FILE *f, fmt::format_string fmt, T &&...args) { - static auto try_print_exception = 1; + static auto try_print_exception = true; + auto wanna_die = false; + try { fmt::print(f, fmt, std::forward(args)...); } catch (const fmt::format_error &err) { if (try_print_exception) { - if (fprintf(f, "Format error: %s\n", err.what()) < 0) { - try_print_exception = 0; + if (fprintf(stderr, "Format error: %s\n", err.what()) < 0) { + try_print_exception = false; } } } catch (std::system_error &err) { + wanna_die = true; if (try_print_exception) { - if (fprintf(f, "System error: %s\n", err.what()) < 0) { - try_print_exception = 0; + if (fprintf(stderr, "System error: %s\n", err.what()) < 0) { + try_print_exception = false; } } } catch (...) { + wanna_die = true; if (try_print_exception) { - if (fprintf(f, "Unknown format error\n") < 0) { - try_print_exception = 0; + if (fprintf(stderr, "Unknown format error\n") < 0) { + try_print_exception = false; } } } + + if (wanna_die) { + exit(EXIT_FAILURE); + } } using sort_lambda = std::function;