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

Prettyerrors #844

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Prettyerrors #844

wants to merge 2 commits into from

Conversation

jw3126
Copy link
Contributor

@jw3126 jw3126 commented Oct 2, 2020

On master the following snippet:

using PyCall
py"""
def raise_multi_line_error():
    raise Exception("1\n2\n3\n4\n")
"""
py"raise_multi_line_error"()

gives

ERROR: LoadError: PyError ($(Expr(:escape, :(ccall(#= /home/jan/.julia/dev/PyCall/src/pyfncall.jl:43
 =# @pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, pyargsptr, kw))))) <class 'Exception'>
Exception('1\n2\n3\n4\n')
  File "/home/jan/.julia/dev/PyCall/src/pyeval.jl", line 2, in raise_multi_line_error
    const Py_file_input = 257

This is hard to read. See also #843 . With this PR it becomes:

ERROR: LoadError: PyError:
1
2
3
4

  File "/home/jan/.julia/dev/PyCall/src/pyeval.jl", line 2, in raise_multi_line_error
    const Py_file_input = 257

end

function Base.showerror(io::IO, e::PyError)
println(io, "PyError:\n", pystr_nofail(e.val))
Copy link
Contributor Author

@jw3126 jw3126 Oct 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is crucial. e.val is the python exception object. And the question is how should we print it. Master does it calling repr. From looking at some tutorials, it seems that calling str is preferred. But I am by no means sure if it is the best analog of showerror in python. Or if it even depends on the python version, what's the preferred thing.

Copy link
Contributor Author

@jw3126 jw3126 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is a bit quick and dirty and there are no tests. I would like to have some feedback about how errors should look like and if this is the right approach, before I clean it up.

@jw3126
Copy link
Contributor Author

jw3126 commented Oct 9, 2020

Is there interest in this PR?

@jw3126
Copy link
Contributor Author

jw3126 commented Oct 12, 2020

@stevengj can you briefly comment if there is interest in this PR? So I know if I should polish / redesign / abandon it.

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.

1 participant