From 357f7105bdc2f328df0fee0c9abb1e757801e187 Mon Sep 17 00:00:00 2001 From: Dianne Skoll Date: Thu, 22 May 2025 10:03:32 -0400 Subject: [PATCH] Better coerce error messages. --- src/funcs.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/funcs.c b/src/funcs.c index 732fc75f..af17502e 100644 --- a/src/funcs.c +++ b/src/funcs.c @@ -563,20 +563,29 @@ static int FDateTime(func_info *info) static int FCoerce(func_info *info) { char const *s; - + char const *v = PrintValue(&(ARG(1)), NULL); ASSERT_TYPE(0, STR_TYPE); s = ARGSTR(0); + int r = OK; + /* Copy the value of ARG(1) into RetVal, and make ARG(1) invalid so it won't be destroyed */ DCOPYVAL(RetVal, ARG(1)); - if (! StrCmpi(s, "int")) return DoCoerce(INT_TYPE, &RetVal); - else if (! StrCmpi(s, "date")) return DoCoerce(DATE_TYPE, &RetVal); - else if (! StrCmpi(s, "time")) return DoCoerce(TIME_TYPE, &RetVal); - else if (! StrCmpi(s, "string")) return DoCoerce(STR_TYPE, &RetVal); - else if (! StrCmpi(s, "datetime")) return DoCoerce(DATETIME_TYPE, &RetVal); - else return E_CANT_COERCE; + if (! StrCmpi(s, "int")) r = DoCoerce(INT_TYPE, &RetVal); + else if (! StrCmpi(s, "date")) r = DoCoerce(DATE_TYPE, &RetVal); + else if (! StrCmpi(s, "time")) r = DoCoerce(TIME_TYPE, &RetVal); + else if (! StrCmpi(s, "string")) r = DoCoerce(STR_TYPE, &RetVal); + else if (! StrCmpi(s, "datetime")) r = DoCoerce(DATETIME_TYPE, &RetVal); + else { + Eprint("coerce(): Invalid type `%s'", s); + return E_CANT_COERCE; + } + if (r) { + Eprint("coerce(): Cannot convert %s to %s", v, s); + } + return r; } /***************************************************************/