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

Raise Pythonic exceptions in JDBCBackend #296

Open
khaeru opened this issue Mar 27, 2020 · 0 comments
Open

Raise Pythonic exceptions in JDBCBackend #296

khaeru opened this issue Mar 27, 2020 · 0 comments
Labels
backend.jdbc Interaction with ixmp_source via JDBCBackend & JPype enh New features & functionality

Comments

@khaeru
Copy link
Member

khaeru commented Mar 27, 2020

The Java code in iiasa/ixmp_source that underlies JDBCBackend raises a variety of exceptions.
JDBCBackend itself has to catch, inspect, and re-raise these in order to give standard Python exceptions—for instance, any add_*() call that gives an invalid name for a Scenario item (set, parameter, etc.) should raise a KeyError; if the user gives malformed data, instead a ValueError, etc.

ixmp/ixmp/backend/jdbc.py

Lines 146 to 154 in 3e16ec8

# NB Much of the code of this backend is in Java, in the iiasa/ixmp_source
# Github repository.
#
# Among other abstractions, this backend:
#
# - Handles any conversion between Java and Python types that is not
# done automatically by JPype.
# - Catches Java exceptions such as ixmp.exceptions.IxException, and
# re-raises them as appropriate Python exceptions.

As noted by @zikolach at #289 (comment), this is unwieldy. It would be better if ixmp_source was adjusted to raise Pythonic exceptions that could be more or less passed through, without the need for JDBCBackend to interpret the messages to determine the correct class.

This also requires updating the spec in backend.base.Backend to specify what exceptions should be raised.

@khaeru khaeru added the enh New features & functionality label Mar 27, 2020
@khaeru khaeru added the backend.jdbc Interaction with ixmp_source via JDBCBackend & JPype label Apr 27, 2020
khaeru added a commit that referenced this issue May 25, 2021
khaeru added a commit that referenced this issue Jul 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend.jdbc Interaction with ixmp_source via JDBCBackend & JPype enh New features & functionality
Projects
None yet
Development

No branches or pull requests

1 participant