Make log warning about bad gnc_numeric print the actual error code.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20281 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Christian Stimming 2011-02-12 15:53:37 +00:00
parent 4741dc2b42
commit 5f7e50efef
3 changed files with 29 additions and 3 deletions

View File

@ -1297,7 +1297,8 @@ PrintAmountInternal(char *buf, gnc_numeric val, const GNCPrintAmountInfo *info)
if (gnc_numeric_check (val))
{
PWARN ("Bad numeric.");
PWARN ("Bad numeric: %s.",
gnc_numeric_errorCode_to_string(gnc_numeric_check (val)));
*buf = '\0';
return 0;
}
@ -1335,7 +1336,8 @@ PrintAmountInternal(char *buf, gnc_numeric val, const GNCPrintAmountInfo *info)
/* Yes, rounding up can cause overflow. Check for it. */
if (gnc_numeric_check(val))
{
PWARN("Bad numeric from rounding.");
PWARN ("Bad numeric from rounding: %s.",
gnc_numeric_errorCode_to_string(gnc_numeric_check (val)));
*buf = '\0';
return 0;
}
@ -1346,7 +1348,8 @@ PrintAmountInternal(char *buf, gnc_numeric val, const GNCPrintAmountInfo *info)
val = gnc_numeric_sub (val, whole, GNC_DENOM_AUTO, GNC_HOW_RND_NEVER);
if (gnc_numeric_check (val))
{
PWARN ("Problem with remainder.");
PWARN ("Problem with remainder: %s.",
gnc_numeric_errorCode_to_string(gnc_numeric_check (val)));
*buf = '\0';
return 0;
}

View File

@ -1507,4 +1507,23 @@ main(int argc, char ** argv)
}
#endif
const char* gnc_numeric_errorCode_to_string(GNCNumericErrorCode error_code)
{
switch (error_code)
{
case GNC_ERROR_OK:
return "GNC_ERROR_OK";
case GNC_ERROR_ARG:
return "GNC_ERROR_ARG";
case GNC_ERROR_OVERFLOW:
return "GNC_ERROR_OVERFLOW";
case GNC_ERROR_DENOM_DIFF:
return "GNC_ERROR_DENOM_DIFF";
case GNC_ERROR_REMAINDER:
return "GNC_ERROR_REMAINDER";
default:
return "<unknown>";
}
}
/* ======================== END OF FILE =================== */

View File

@ -275,6 +275,10 @@ gboolean string_to_gnc_numeric(const gchar* str, gnc_numeric *n);
* noted by error_code, rather than a number.
*/
gnc_numeric gnc_numeric_error(GNCNumericErrorCode error_code);
/** Returns a string representation of the given GNCNumericErrorCode.
*/
const char* gnc_numeric_errorCode_to_string(GNCNumericErrorCode error_code);
/** @} */
/** @name Value Accessors