From: Alan T. DeKok Date: Sat, 1 Feb 2025 16:47:39 +0000 (-0500) Subject: better error message when parsing time deltas X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ea143a84ec9f9ba6c7f0b00f8854feb09ad182e9;p=thirdparty%2Ffreeradius-server.git better error message when parsing time deltas "token not found" is technically correct, but isn't helpful --- diff --git a/src/lib/util/time.c b/src/lib/util/time.c index 232876f37c5..6c8e72e674a 100644 --- a/src/lib/util/time.c +++ b/src/lib/util/time.c @@ -226,9 +226,16 @@ fr_slen_t fr_time_delta_from_substr(fr_time_delta_t *out, fr_sbuff_t *in, fr_tim negative = fr_sbuff_is_char(&our_in, '-'); if (fr_sbuff_out(&sberr, &integer, &our_in) < 0) { + char const *err; + num_error: - fr_strerror_printf("Failed parsing time_delta: %s", - fr_table_str_by_value(sbuff_parse_error_table, sberr, "")); + if (sberr != FR_SBUFF_PARSE_ERROR_NOT_FOUND) { + err = fr_table_str_by_value(sbuff_parse_error_table, sberr, ""); + } else { + err = "Invalid text, input should be an integer"; + } + + fr_strerror_printf("Failed parsing time_delta: %s", err); FR_SBUFF_ERROR_RETURN(&our_in); } fr_sbuff_out_by_longest_prefix(&match_len, &res, fr_time_precision_table, &our_in, FR_TIME_RES_INVALID); diff --git a/src/tests/unit/data_types.txt b/src/tests/unit/data_types.txt index 343cc93a3ed..b956b244999 100644 --- a/src/tests/unit/data_types.txt +++ b/src/tests/unit/data_types.txt @@ -31,6 +31,9 @@ match 1 value time_delta 2.4 match 2.4 +value time_delta yes +match Failed parsing time_delta: Invalid text, input should be an integer + value time_delta 1ms match 0.001 @@ -244,4 +247,4 @@ encode-dns-label www_foo.com match Invalid character 0x5f in label count -match 120 +match 122