Skip to content

Conversation

@Carreau
Copy link
Member

@Carreau Carreau commented Jul 25, 2012

by default %%javascript will publish it's content in a try/catch and
display a warning in cell output if the expression raises.

This is should prevent some sneeky JS to prevent notebook to load.
and give more feedback to the user.

%%javascript
a.a=1

shows

ReferenceError: a is not defined
See your frontend Javascript console for more details.

@takluyver
Copy link
Member

In terms of the error message, I would say 'browser' is more clear than 'frontend'. Anyone using something other than a browser probably knows enough to work out where to look for errors.

@Carreau
Copy link
Member Author

Carreau commented Jul 25, 2012

fixed.

@minrk
Copy link
Member

minrk commented Jul 25, 2012

There is no difference between javascript from %%javascript and from display(JS('...')), so why should we treat them differently? They should probably have all the same protections, etc.

@Carreau
Copy link
Member Author

Carreau commented Jul 25, 2012

IMHO, the use of display(JS('...')) would be for tested script and library, but %%js magic is more for testing.
So I could put the same logic in JS but then I would default the flag to not wrap.

@minrk
Copy link
Member

minrk commented Jul 25, 2012

Also, how can this prevent notebooks from loading? displayed JS is not run when a notebook is first loaded.

@Carreau
Copy link
Member Author

Carreau commented Jul 25, 2012

Am I mistaking displayed JS with markdown JS ?
I had some notebook that where not loading because of JS, but I don't remember if it was because of markdown or display(JS(...)) during SciPy when I was building the slideshow extension.

@minrk
Copy link
Member

minrk commented Jul 25, 2012

Yes, I think so - markdown js is totally unprotected, and can bork the whole thing (something we really should protect against). Errors in your JS (%%javascript or display(JS)) don't seem to be able to cause any problems, at load time or run time.

@Carreau
Copy link
Member Author

Carreau commented Jul 25, 2012

Moved logic into Js object.

@minrk
Copy link
Member

minrk commented Jul 25, 2012

Are you sure it belongs in the JS object, and not the frontend itself?

@Carreau
Copy link
Member Author

Carreau commented Jul 25, 2012

I don't wan't to force people to publish protected javascript, or at least give them a way to disable it.
I've not enough experience with JS to find a valid reason why you wouldn't accept to do so...
But If enough people are fine with putting it in the frontend, I'll do it.

@Carreau
Copy link
Member Author

Carreau commented Jul 27, 2012

So do we implement this one in kernel or in frontend ?

@minrk
Copy link
Member

minrk commented Jul 27, 2012

#2212 protects markdown cells from javascript errors. Personally, I don't think display(JS) needs any protecting, since I don't think it can actually cause problems, can it?

@Carreau
Copy link
Member Author

Carreau commented Jul 27, 2012

it still warns you that you made a mistake ...

@Carreau
Copy link
Member Author

Carreau commented Jul 27, 2012

Would you like ipython to catch you traceback ?

@minrk
Copy link
Member

minrk commented Jul 27, 2012

That's a good point. I imagine some folks would like a traceback.

@Carreau
Copy link
Member Author

Carreau commented Jul 27, 2012

Made on browser side only.

Copy link
Member

Choose a reason for hiding this comment

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

Let's use a CSS class here ('js-error'?), instead of direct attrs.

Copy link
Member Author

Choose a reason for hiding this comment

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

when yours is merged, i'll do

.render-error, .js-error{
...
}

For now, I'll go to sleep.

Copy link
Member

Choose a reason for hiding this comment

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

Seems like render-error in the other branch should be called js-error. Aren't they really the same thing?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I will change that one to match.

-MinRK

On Jul 27, 2012, at 17:28, "Brian E. Granger"reply@reply.github.com wrote:

@@ -360,7 +360,19 @@ var IPython = (function (IPython) {
container.hide();
// If the Javascript appends content to element that should be drawn, then
// it must also call container.show().

  •    eval(js);
    
  •    try {
    
  •        eval(js);
    
  •    } catch(err) {
    
  •        console.log('Error in Javascript!');
    
  •        console.log(err);
    
  •        container.show();
    
  •        element.append($('<div/>')
    
  •            .html("Error in Javascript !<br/>"+
    
  •                err.toString()+
    
  •                '<br/>See your browser Javascript console for more details.')
    
  •            .attr('style','color:darkred')
    

Seems like render-error in the other branch should be called js-error. Aren't they really the same thing?


Reply to this email directly or view it on GitHub:
https://github.com/ipython/ipython/pull/2199/files#r1257667

@Carreau
Copy link
Member Author

Carreau commented Jul 28, 2012

ok, rebase on top on Min's one that catch js in markdown.
It now uses the same css class.

I'll merge.

Carreau added a commit that referenced this pull request Jul 28, 2012
Wrap published javascript in try/catch to show a error if it raises.
@Carreau Carreau merged commit 94a7f6c into ipython:master Jul 28, 2012
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014
Wrap published javascript in try/catch to show a error if it raises.
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.

4 participants