Skip to content

Feature: Return errors separately #17

@ericallam

Description

@ericallam

It would be nice if it were possible to tell the difference between when code resulted in an error and when it successfully returned a value. I'm thinking of something like this:

var engine = require("engine.js").engine;
var client = engine.client.create();

var task = client.createTask();
task.setContext("(function(locals){ return { add: function(a,b){ return a+b } } })");
task.setLocals({});
task.setCode('sub(1,2)');        

task.on('eval', function(err, data){
  if(err) console.log(err); // ReferenceError: sub is not defined
  console.log(data) // undefined
});

task.run();

Or maybe a different event:

task.on('eval', function(data){
  console.log(data);
});

task.on('error', function(err){
  console.log(err); // ReferenceError: sub is not defined
});

I think I should be able to implement this feature and will submit a pull request when I get a chance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions