Repository navigation
Do not show exception in non-debugging mode - #160
Conversation
| self._debug("Retrieving exception infos...") | ||
| stderr = self.api.jl_stderr_obj() | ||
| self._debug("libjulia stderr = " + str(stderr)) | ||
| self.api.jl_call2(self.api.show, stderr, exoc) |
There was a problem hiding this comment.
I just need to wrap self._debug("libjulia stderr = " + str(stderr)) in if self.is_debugging: but I find wrapping the whole debug related code makes code easier to read.
There was a problem hiding this comment.
I get the impression that the only point of this call to self.api.show in the first place was to make sure that the whole Julia exception is printed — maybe this code can simply be deleted now that showerror is included in the Python exception?
|
I don't agree with this change. If you evaluate Julia code and it throws an exception, then the exception should be shown — in fact, it should probably be converted to a Python exception and thrown in Python. (When you evaluate Python code that throws an exception, it is not generally hidden from the caller, and pyjulia should be no different.) If import is printing an excessive number of exception messages, then import should be fixed. |
It is raised as Python exception at the end of Lines 426 to 432 in 2eb704c This is just below the code I edited. The quirk in pyjulia I reported in #159 is that the error in Julia reported twice: first via |
|
Ah, okay. But in that case the actual Julia exception output should probably be put into the exception text rather than into debugging output, via something like: instead of |
|
So I implemented what you suggested but actually I'm not sure if it is the best way to go, since, in principle, I think a better approach would be to define a helper Julia function/macro that evals the code and wraps the result into a "Result" struct, something like struct Result{T}
result :: Nullable{T}
error :: String
endwhere |
|
(Actually, retrieving |
| if res is None: | ||
| exception = self.api.jl_typeof_str(exoc).decode('utf-8') | ||
| else: | ||
| exception = self.sprint(self.showerror, self._as_pyobj(res)) |
There was a problem hiding this comment.
Oh, nevermind, I see that exoc is a raw Julia pointer.
| # self.api.jl_printf(self.api.jl_stderr_stream(), "\n"); | ||
|
|
||
| exception_type = self.api.jl_typeof_str(exoc).decode('utf-8') | ||
| res = self.api.jl_call2(void_p(self.api.convert), void_p(self.api.PyObject), void_p(exoc)) |
There was a problem hiding this comment.
Probably should be self.api.jl_call1(void_p(self.api.PyObject), void_p(exoc)) (the convert method may go away in a future PyCall version, since this is really a constructor call)
There was a problem hiding this comment.
I'm a little worried about the interaction of this raw jl_value_t* manipulation with garbage collection in Julia, but I guess that's something that needs to be fixed more generally.
There was a problem hiding this comment.
Hmm.... It segfaults somehow when I apply your suggestion tkf@e8da821
Also, I should say I'm not fully aware of how Julia's GC works and how GCs of Julia and Python interact in PyCall.jl and pyjulia. I just followed the similar existing code in pyjulia. I'd be a lot more confident if you can pull only the first commit.
There was a problem hiding this comment.
Reading git blame, it looks like it is changed from self.api.jl_call1(void_p(self.api.PyObject), void_p(ans)) to self.api.jl_call2(void_p(self.api.convert), void_p(self.api.PyObject), void_p(ans)) in 0912ac4#diff-2f4f81856f2b92c6a4bb1e5bba2cf28aR380 by @Keno (PR #54). Not clear why from git message.
There was a problem hiding this comment.
Maybe jl_call1 only works for actual Function objects these days, and we'll have to dig to find out how to call the constructor. Let's continue to use convert for now, I guess.
> the convert method may go away in a future PyCall version, since this > is really a constructor call > > --- @stevengj > JuliaPy#160 (comment)
|
@stevengj Are there any other issues to be solved before merging it? |
|
As mentioned above, I think the |
|
Sorry, I didn't notice that comment. I forgot GitHub issue is not linearizing the comments... I thought it could be useful in some edge cases. For example, if an error occurred during (...which makes me realize that I should make sure that they exist before using it; tweaked the code) Having said that, I'm not the one maintaining the code so I'm happy with removing |
|
I guess CI is broken right now, but is it possible to add a test? For example, sqrt(-1) throws. |
|
There is already a test: Lines 27 to 32 in 2eb704c I tested it locally. |
|
I made the test a bit more specific to make sure we call |
|
Thanks! |
1 similar comment
|
Thanks! |
fixes #159