Skip to content

Fix exception handling for JPype 0.7#108

Closed
baztian wants to merge 2 commits intomasterfrom
fix-exceptions-for-new-jpype
Closed

Fix exception handling for JPype 0.7#108
baztian wants to merge 2 commits intomasterfrom
fix-exceptions-for-new-jpype

Conversation

@baztian
Copy link
Owner

@baztian baztian commented Jul 8, 2019

thanks @Thrameos for pointing out the issue (#102)

@baztian baztian force-pushed the fix-exceptions-for-new-jpype branch from 594a4d7 to c72f00a Compare July 8, 2019 20:57
@baztian baztian force-pushed the fix-exceptions-for-new-jpype branch from c72f00a to f603890 Compare July 8, 2019 21:13
@baztian
Copy link
Owner Author

baztian commented Jul 8, 2019

@Thrameos you mentioned some exception handling changes in #102. I don't really get how it changed. Also it's been a while back I wrote the exception handling code.
Can you please give me some advice on how to change the code accordingly?

@Thrameos
Copy link
Contributor

Thrameos commented Jul 8, 2019

Should be covered in jpype-project/jpype#498 and pyathena-dev/PyAthenaJDBC#85

The original exception code caught a dummy class that held the real exception as the first argument but the version directly throws the exception. There was a common pattern that both versions are supposed to be able to use using JException, but thus far I have seen a lot of code that get into the arguments.

Hopefully these two threads have enough to help. If not just reply an I will take a deeper look at your structure.

@baztian
Copy link
Owner Author

baztian commented Jul 9, 2019

Thanks @Thrameos. I tried two different approaches to deal with exceptions in this PR. Looking deeper into it it seems I'm (now) catching the exceptions correctly. But the unit test uses str/toString on the exception and is getting the wrong output. The code works with the older JPypes and with Jython.

The output of the test can be found in the travis job output.

It seems to be a JPype 0.7 shortcomming. Can you please have another look on this?

@baztian
Copy link
Owner Author

baztian commented Jul 9, 2019

One other thing in JPype 0.7 I don't really get is that string conversion seems to be changed for non Pyhton 3 versions. https://travis-ci.org/baztian/jaydebeapi/jobs/556477652#L286 works with the old JPype version: https://travis-ci.org/baztian/jaydebeapi/jobs/556477652#L498
@Thrameos any ideas?

@Thrameos
Copy link
Contributor

Thrameos commented Jul 9, 2019

Well str(exception) should be calling exception.toString() which should be what you expect. It looks like there may be a bug in jpype with this regard.

Seems like the line 65 in jpype/_jexception.py

     def __str__(self):
        return str(self.getMessage())

should read as

     def __str__(self):
        return str(self.toString())

@Thrameos
Copy link
Contributor

Thrameos commented Jul 9, 2019

As to the other question, are you referring to string conversions in general such as returning java.lang.String rather than Python strings or something else?

@baztian
Copy link
Owner Author

baztian commented Jun 10, 2020

I'm going to ignore that issue with 0.7.0 and test against 0.7.1. #151 will fix the build

@baztian baztian closed this Jun 11, 2020
@baztian baztian deleted the fix-exceptions-for-new-jpype branch June 11, 2020 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants