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

No error bubbling? #61

Open
janfreyberg opened this issue Dec 26, 2019 · 11 comments
Open

No error bubbling? #61

janfreyberg opened this issue Dec 26, 2019 · 11 comments

Comments

@janfreyberg
Copy link

Hi, if an exception is thrown during an interactive action, such as a callback invoked by Canvas.on_mouse_down, there seems to be no way of knowing this.

e.g.:

from ipycanvas import Canvas

def callback(*args):
    raise ValueError("Invisible")

c = Canvas(size=(500, 500))
c.on_mouse_down(callback)
c

by contrast, errors in ipywidgets.Button calls are reported in the jupyter lab log:

from ipywidgets import Button
b = Button(description='Hi')

def callback(*args):
    raise ValueError("Invisible")

b.on_click(callback)
b

image

Is it possible to match this behaviour?

@martinRenou
Copy link
Collaborator

Thanks a lot for opening an issue. I suppose this is unexpected behavior. I am not sure what is causing this. I will have a look in two weeks.

@martinRenou
Copy link
Collaborator

That is really weird. I could also see something similar in ipyleaflet today, see jupyter-widgets/ipyleaflet#455 (comment).

I really don't know where this comes from.

Maybe you already know about it, but you can use the Output widget in order to capture the stream explicitly, and put it where you want.

@janfreyberg
Copy link
Author

Yes - the issue is more for debugging when it's hard to know where to capture output. I don't know why this might be happening, but the jupyter lab log console is discussed here: jupyterlab/jupyterlab#7386

They specifically mention un-handled messages being logged; I don't know how a message being "handled" is defined though.

@kenseehart
Copy link

kenseehart commented May 9, 2020

Here's my workaround:

import traceback

class MyUI:
    def __init__(self, canvas, model):
        self.canvas = canvas
        self.model = model
        canvas.on_mouse_down(self.mouse_down)

    def mouse_down(self, x, y):
        try:
            do_some_stuff()
        except:
            self.print_traceback()
            
    def print_traceback(self):
        self.canvas.fill_style = '#ff8888'
        self.canvas.fill_rect(10, 10, 300, 300)
        self.canvas.fill_style = '#000000'
        s = traceback.format_exc()
        for i, si in enumerate(s.split('\n')):
            canvas.fill_text(si, 20, 30+15*i)    

Works great. Now my code is debugable.

@kenseehart
Copy link

Looks like the CallbackDispatcher is consuming stdin and stdout for some reason. It's not about exceptions per se. Probably the exception is be handled in the normal way, but when the traceback is written to stdout, it gets consumed.

@janfreyberg
Copy link
Author

that's a really neat workaround, thanks @kenseehart

@ianhi
Copy link
Contributor

ianhi commented Jul 21, 2020

The CallbackDispatcher is being created a little bit differently in ipycanvas and the ipywidgets button. In the button it is created in the constructor:
https://github.com/jupyter-widgets/ipywidgets/blob/6be18d9b75353f7b4a1c328c6ea06d8959f978f6/ipywidgets/widgets/widget_button.py#L57-L60

whereas here it is wrapped in at traitlets Instance function and explicitly added:
https://github.com/martinRenou/ipycanvas/blob/a97d7810745afb61e4daed71bd92b998304e36fd/ipycanvas/canvas.py#L180

@martinRenou
Copy link
Collaborator

@ianhi do you think that could be the cause of the issue?

Indeed having the object instantiated as a kind-of static property does not sound right at all.

@ianhi
Copy link
Contributor

ianhi commented Jul 21, 2020

@martinRenou oops I forgot to include any context for that comparison. Yes, my intention was to imply that this may be the cause as this seems to be the only relevant difference between ipycanvas and the ipywidgets.Button

@ahrm
Copy link

ahrm commented Feb 24, 2021

Hi! Why is this issue closed? Is it fixed in the new versions?

@ianhi
Copy link
Contributor

ianhi commented Feb 24, 2021

Hi @ahrm this issue is still open. You see this at the top of the page:
image

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

No branches or pull requests

5 participants