Skip to content
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

Proper error handling for currencies #107

Closed
sharkdp opened this issue Jul 12, 2023 · 1 comment
Closed

Proper error handling for currencies #107

sharkdp opened this issue Jul 12, 2023 · 1 comment
Labels

Comments

@sharkdp
Copy link
Owner

sharkdp commented Jul 12, 2023

For now, we set the conversion factor to NaN in case of ANY errors (e.g. http request failed, parsing failed, etc). How can we properly handle errors here?

@sharkdp
Copy link
Owner Author

sharkdp commented Sep 26, 2023

One way to do this would be the following:

  • We do not load currency exchange rates by default
  • When we see an error that indicates that the user wants to use one of the currency units from units::currencies (e.g. unknown identifier 'USD', where we would look out for all identifiers that the module defines), we suppress that error message, and try to load the currency exchange rates synchronously.
  • If fetching exchange rates (or parsing the XML) fails for some reason, we show a runtime error message ("could not fetch …"). We do not show the "unknown identifier …" message.
  • If fetching exchange rates succeeds, we then load the units::currencies module and subsequently re-try to evaluate the user expression. This time, it should succeed.

This solves multiple problems:

  • Proper error messages in case fetching exchange rates fails. No NaN values.
  • No need to bother the user with "could not fetch…" messages if they don't want to work with currencies
  • No asynchronous loading of modules (we might even be able to get rid of some synchronization mechanisms?)
  • Consequently, no problems with immediate availability of currency units (numbat -e '150 € to $ would work)

Disadvantages:

  • we need to know all identifiers that the units::currencies module provides.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant