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

Doesn't throw in functions #9

Open
Z3TA opened this issue Sep 10, 2017 · 5 comments
Open

Doesn't throw in functions #9

Z3TA opened this issue Sep 10, 2017 · 5 comments

Comments

@Z3TA
Copy link

Z3TA commented Sep 10, 2017

Example code:
`

const Iroh = require("iroh");

let stage = new Iroh.Stage(function foo() { throw "banana"; } foo(););

eval(stage.script);

`
The exception will be ignored!

@Z3TA
Copy link
Author

Z3TA commented Sep 10, 2017

I've tracked it to function DEBUG_FUNCTION_CALL, where theres a try catch ...
Maybe make it possible to listen for errors ... !? hmm

@maierfelix
Copy link
Owner

I'm working on it

@maierfelix
Copy link
Owner

Errors shouldn't be suppressed anymore with 3edc548

@Z3TA
Copy link
Author

Z3TA commented Sep 10, 2017

I think "throw" outside a try should generate an Iroh.PROGRAM "exception" event

That way you can listen for it and get the source location and maybe even a call stack.

@maierfelix
Copy link
Owner

maierfelix commented Sep 10, 2017

This would require to patch a try {} around the submitted code, which would break global variable/function support. However I experimented a bit and came up with this:

let stage = new Iroh.Stage(code);
stage.addListener(Iroh.PROGRAM)
.on("error", (e) => {
  console.error(e.error);
});

try {
  eval(stage.script);
} catch (e) {
  let event = stage.createEvent(Iroh.PROGRAM_ERROR);
  event.indent = stage.indent;
  event.error = e;
  event.trigger("error");
}

So if you want to listen for uncatched errors in your program, you have to evaluate your program this way, which remains global support but requires some additional code lines.

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

2 participants