Skip to content

Commit

Permalink
[Minor] Improve diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
vstakhov committed Oct 24, 2023
1 parent 9873ef9 commit 6b81b81
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/client/rspamc.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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 *)>;
Expand Down

0 comments on commit 6b81b81

Please sign in to comment.