summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2023-10-24 16:02:59 +0100
committerVsevolod Stakhov <vsevolod@rspamd.com>2023-10-24 16:02:59 +0100
commit6b81b812a7a34ad7201b7df214bb543d089d7919 (patch)
tree680c1477cfcd102ec9276f7f63f3c38a08a18bc7
parent9873ef954ffa406e9c860b0023af88f7f2e627e8 (diff)
downloadrspamd-6b81b812a7a34ad7201b7df214bb543d089d7919.tar.gz
rspamd-6b81b812a7a34ad7201b7df214bb543d089d7919.zip
[Minor] Improve diagnostics
-rw-r--r--src/client/rspamc.cxx22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/client/rspamc.cxx b/src/client/rspamc.cxx
index cf2f9d1dc..50e3cbdee 100644
--- a/src/client/rspamc.cxx
+++ b/src/client/rspamc.cxx
@@ -365,28 +365,36 @@ struct fmt::formatter<rspamd_action_type> : fmt::formatter<string_view> {
template<typename... T>
static inline void rspamc_print(std::FILE *f, fmt::format_string<T...> 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<T>(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<int(const ucl_object_t *, const ucl_object_t *)>;