-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle exceptions when retrieving account balances #68
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your PR! I added to questions.
These are mainly aimed at finding out how these errors can happen, since this affects how to best handle them. Can this happenthrough normal user operation? Are they the result of a corrupted database or a bug?
if amount is None: | ||
return Markup('<span class="text-danger">Error</span>') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In which cases can the amount be None? Is it an invalid database then? Do you know how one arrives at such a state?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a GnucashException
was raised, the safe_get_balance
filter returns None as an amount.
except GnucashException as e: | ||
logging.warning(f"Failed to retrieve balance for account {account}: {e}") | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar question: What are the circumstances that lead to an exception in this case. Invalid database? Can this happen when using simply the GnuCash Desktop-App and gnucash_web?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Piecash raises this exception when there is no direct exchange rate between two currencies. This can occur in legitimate scenarios and is not necessarily due to an invalid database.
In my case, I had a EUR account with a USD account as its parent. Neither of these currencies is the default currency in my GnuCash book; the default is CAD. As a result, I only had conversion rates for USD-CAD and EUR-CAD, but not for USD-EUR. When attempting to read this database in gnucash-web, the absence of a direct exchange rate caused an unhandled exception, resulting in an HTTP 500 error.
This database was created entirely using the GnuCash desktop app and has not been modified by any other tool.
This PR adds a
safe_get_balance
Jinja filter to handle exceptions raised byAccount.get_balance()
. When an exception occurs, the balance field now shows "Error" instead of causing an HTTP 500 error.