From dd1b96b03b5476d71ece4f34717c4dc69a50d9cf Mon Sep 17 00:00:00 2001 From: Eero Tamminen Date: Fri, 15 Dec 2023 19:18:54 +0100 Subject: [PATCH] format_json: Move conditional error logging to a separate function. This reduces the amount of duplicate code being generated. Co-authored-by: Florian Forster --- src/utils/format_json/open_telemetry.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/utils/format_json/open_telemetry.c b/src/utils/format_json/open_telemetry.c index 5f0af1e50..1e45f144a 100644 --- a/src/utils/format_json/open_telemetry.c +++ b/src/utils/format_json/open_telemetry.c @@ -30,13 +30,18 @@ #include +static void log_yajl_gen_error(int line, const char *fname, int status) { + if (strncmp(fname, "yajl_gen_", strlen("yajl_gen_")) != 0) { + return; + } + ERROR("open_telemetry.c:%d: %s failed with status %d", line, fname, status); +} + #define CHECK(f) \ do { \ int status = (f); \ if (status != 0) { \ - if (strncmp(#f, "yajl_gen_", strlen("yajl_gen_")) == 0) { \ - ERROR("format_json: %s failed with status %d", #f, status); \ - } \ + log_yajl_gen_error(__LINE__, #f, status); \ return status; \ } \ } while (0) -- 2.39.5