hpi-swa / ipolyglot

A polyglot kernel for Jupyter notebooks based on GraalVM.
Other
91 stars 4 forks source link

Handle cell ouput across languages. #13

Open niconomaa opened 5 years ago

niconomaa commented 5 years ago

Errors are returned inconsistently depending on the language used in the kernel cell. Consistent and useful error messages are desired.

jonashering commented 5 years ago

Initial idea was to call language specific String representation methods (such as obj.__repr__() for e.g. python) on foreign objects that ijavascript could not evaluate with default obj.inspect as implemented on feature branch #13. Will revert back to " " + obj as this seems to be cleaner approach.

JakobEdding commented 5 years ago

In this comment, we try to consolidate observations of different behaviors of output / error handling across languages.

We also compare the output / error handling inside Jupyter Notebook to the behavior when using the Polyglot.eval interface inside a console node --polyglot --jvm session to potentially spot errors which are not caused by our implementation but instead by GraalVM.

Python - stdout - Jupyter Notebook ❌

Output of print() is not shown, NEL internal error because the execution of the last line doesn't yield anything which can be automatically converted and shown as cell output (yields null instead).

image

Python - stdout - Console ✅

Behaves as expected.

> result = Polyglot.eval('python', 'a = 0\nprint(a)\na += 1');
0
null

Python - stderr - Jupyter Notebook ✅

Behaves as expected.

image

Python - stderr - Console ✅

Behaves as expected.

> result = Polyglot.eval('python', '<----');
Error: SyntaxError: invalid syntax
    at Object.eval (native)

Ruby - stdout - Jupyter Notebook ❌

Output of puts is not shown

image

Ruby - stdout - Console ✅

Behaves as expected.

> result = Polyglot.eval('ruby', 'a = 0\nputs a\na += 1');
0
1

Ruby - stderr - Jupyter Notebook ❌

No error message in Notebook, NEL internal error on Node console, kernel is stuck in execution and is unresponsive.

image

Ruby - stderr - Console ❌

Unrelated JS error is shown.

> result = Polyglot.eval('ruby', '<----');
TypeError: Object prototype may only be an Object or null: DynamicObject@5d75f90e<Method>
    at Function.setPrototypeOf (native)
    at deprecate (internal/util.js:70:10)
    at formatValue (internal/util/inspect.js:481:21)
    at Object.inspect (internal/util/inspect.js:191:10)
    at Domain.debugDomainError (repl.js:439:34)
    at Domain.emit (events.js:189:13)
    at Domain.emit (domain.js:441:20)
    at REPLServer.defaultEval (repl.js:353:26)
    at bound (domain.js:395:14)
    at REPLServer.runBound (domain.js:408:12)

R - stdout - Jupyter Notebook ❌

Output of print() is not shown

image

R - stdout - Console ✅

Behaves as expected.

> result = Polyglot.eval('R', 'a = 0\nprint(a)\nb = "asdf"');
[1] 0
'asdf'

R - stderr - Jupyter Notebook ✅

Behaves as expected.

image

R - stderr - Console ✅

Behaves as expected.

> result = Polyglot.eval('R', '<----');
Error: parse exception
    at Object.eval (native)

JS - stdout - Jupyter Notebook ✅

Behaves as expected.

image

JS - stdout - Console ✅

Behaves as expected.

> result = Polyglot.eval('js', 'a = 0\nconsole.log(a)\na += 1');
0
1

JS - stderr - Jupyter Notebook ✅

Behaves as expected.

image

JS - stderr - Console ✅

Behaves as expected.

> result = Polyglot.eval('js', '<----');
Error: SyntaxError: <eval>:1:0 Expected an operand but found <
<----
^

    at Object.eval (native)