You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2018/06/19 16:47:42 UTC

[GitHub] jthomas opened a new issue #63: Thrown errors from async function missing details

jthomas opened a new issue #63: Thrown errors from async function missing details
URL: https://github.com/apache/incubator-openwhisk-runtime-nodejs/issues/63
 
 
   ## Environment details:
   
   IBM Cloud Functions 
   
   ## Steps to reproduce the issue:
   
   Create a function using the Node.js 8 runtime with this code snippet.
   
   ```js
   const main = () => {
       return a.b.c
   }
   ```
   
   Invoking this action, the following activation response is returned.
   ```json
   {
     "error": "An error has occurred: ReferenceError: a is not defined"
   }
   ```
   Stack trace is included in the logs.
   
   ```
   "2018-06-19T16:29:11.783438495Z stderr: ReferenceError: a is not defined"
   "2018-06-19T16:29:11.783496031Z stderr: at NodeActionRunner.main [as userScriptMain] (eval at NodeActionRunner.init (/nodejsAction/runner.js:76:45), <anonymous>:13:5)"
   "2018-06-19T16:29:11.783515019Z stderr: at /nodejsAction/runner.js:95:45"
   ...
   ```
   
   Change the action code to the following source.
   
   ```js
   const main = async () => {
       return a.b.c
   }
   ```
   
   Invoking the updated action, the following activation response is returned.
   
   ```json
   {
     "error": {}
   }
   ```
   
   Nothing is logged to stdout or stderr for this activation.
   
   This also affect all error handling for async functions, where errors are thrown to signal errors from user-land code.
   
   ### cause 
   
   Looking at the code, when an error is thrown from async functions, it ends up in `catch` callback handler @ https://github.com/apache/incubator-openwhisk-runtime-nodejs/blob/master/core/nodejsActionBase/runner.js#L107-L117
   
   It [returns the Error object](https://github.com/apache/incubator-openwhisk-runtime-nodejs/blob/master/core/nodejsActionBase/runner.js#L115) thrown from the async function as the child property of the `error` key in the normal response body.
   
   Error objects serialise to an empty object when converting to JSON, which explains the empty object returned in the activation response.
   
   ```
   > JSON.stringify(new Error('hello'))
   '{}'
   ```
   
   ### fix
   
   Async error should mirror response & log values from normal errors, return `err.message` in result and log stack track. 
   
   ### next steps
   **If people agree with this diagnosis and the suggested resolution, I can try to submit a PR to resolve this?**

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services