TritonDataCenter / node-workflow

Task orchestration, creation and running using NodeJS
MIT License
456 stars 66 forks source link

task callback should support callback(new Error(...)) #82

Closed rgulewich closed 12 years ago

rgulewich commented 12 years ago

If a task body calls the task callback with a regular error, like so:

    callback(new Error('Some error'));

the error reported by the workflow is blank:

    {
      "result": "",
      "error": {},
      "name": "my.task",
      "started_at": "2012-08-14T20:14:17.622Z",
      "finished_at": "2012-08-14T20:14:17.940Z"
    }

If the callback is called with a restify error, the error has useful information:

    {
      "result": "",
      "error": {
        "message": "REST error",
        "body": {
          "code": "InvalidArgument",
          "message": "REST error"
        },
        "httpCode": 409,
        "statusCode": 409,
        "restCode": "InvalidArgument",
        "code": "InvalidArgument"
      },
      "name": "my.task",
      "started_at": "2012-08-14T19:40:38.629Z",
      "finished_at": "2012-08-14T19:40:38.945Z"
    }
kusor commented 12 years ago

With these commits, when the tasks' callback is called with a generic Error instance, (this also includes RangeError, ReferenceError, ... in general, anything which is not a restify.Error), it will now pass Error's name and message properties to the job results like:

{ 
  "name": "Error",
  "message": "Fail task error"
}

I've also tried to pass stack track information to these errors, but it's useless, since we're running code sandboxed using VM API, and the stacks always point to WorkflowTaskRunner.

Let me know if the solution is good enough or we should try to go further adding some extra information.

rgulewich commented 12 years ago

Tried it out this morning, and it worked great. Thanks!