From 1c6c0fbff6305513dbe9f6832159ff593d9bd846 Mon Sep 17 00:00:00 2001 From: Albert Chu Date: Fri, 20 Dec 2024 10:28:12 -0800 Subject: [PATCH 1/2] flux-kvs: improve eventlog error messages Problem: When an improperly formatted eventlog is input into eventlog commands, a non-useful error message is output. Output a better error message. --- src/cmd/flux-kvs.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cmd/flux-kvs.c b/src/cmd/flux-kvs.c index aed951bd21a4..c3b88304d9b7 100644 --- a/src/cmd/flux-kvs.c +++ b/src/cmd/flux-kvs.c @@ -2019,8 +2019,11 @@ void eventlog_get_continuation (flux_future_t *f, void *arg) if (flux_kvs_lookup_get (f, &s) < 0) log_err_exit ("flux_kvs_lookup_get"); - if (!(a = eventlog_decode (s))) + if (!(a = eventlog_decode (s))) { + if (errno == EINVAL) + log_msg_exit ("cannot decode improperly formatted eventlog"); log_err_exit ("eventlog_decode"); + } json_array_foreach (a, index, value) { if (optparse_hasopt (ctx->p, "watch")) { @@ -2135,8 +2138,11 @@ void eventlog_wait_event_continuation (flux_future_t *f, void *arg) log_err_exit ("flux_kvs_lookup_get"); } - if (!(a = eventlog_decode (s))) + if (!(a = eventlog_decode (s))) { + if (errno == EINVAL) + log_msg_exit ("cannot decode improperly formatted eventlog"); log_err_exit ("eventlog_decode"); + } json_array_foreach (a, index, value) { const char *name; From 8d7ad52e2f9028e30cf932bfbccd4cf01e3c149c Mon Sep 17 00:00:00 2001 From: Albert Chu Date: Fri, 20 Dec 2024 10:29:19 -0800 Subject: [PATCH 2/2] t: cover improper kvs eventlogs Problem: The flux kvs eventlog commands don't have coverage for improperly formatted eventlogs. Add some coverage to t1008-kvs-eventlog.t. --- t/t1008-kvs-eventlog.t | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/t/t1008-kvs-eventlog.t b/t/t1008-kvs-eventlog.t index c19f5e229b9c..bb7ac4270b0a 100755 --- a/t/t1008-kvs-eventlog.t +++ b/t/t1008-kvs-eventlog.t @@ -224,6 +224,12 @@ test_expect_success 'flux kvs eventlog get fails on bad input' ' test_must_fail flux kvs eventlog get ' +test_expect_success 'flux kvs eventlog get fails on not an eventlog' ' + flux kvs put test.noteventlog=foo && + test_must_fail flux kvs eventlog get test.noteventlog 2> noteventlog1.err && + grep "cannot decode" noteventlog1.err +' + test_expect_success 'flux kvs eventlog append fails on bad input' ' test_must_fail flux kvs eventlog append ' @@ -236,6 +242,11 @@ test_expect_success 'flux kvs eventlog wait-event fails on bad input' ' test_must_fail flux kvs eventlog wait-event ' +test_expect_success 'flux kvs eventlog wait-event fails on not an eventlog' ' + test_must_fail flux kvs eventlog wait-event test.noteventlog foo 2> noteventlog2.err && + grep "cannot decode" noteventlog2.err +' + # # ensure no lingering pending requests #