jthomas closed pull request #95: Fixes #63 - Support errors thrown from async 
functions
URL: https://github.com/apache/incubator-openwhisk-runtime-nodejs/pull/95
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/core/nodejsActionBase/runner.js b/core/nodejsActionBase/runner.js
index ea869be..1ad7172 100644
--- a/core/nodejsActionBase/runner.js
+++ b/core/nodejsActionBase/runner.js
@@ -114,7 +114,11 @@ function NodeActionRunner() {
                     if (!error) {
                         resolve({ error: {}});
                     } else {
-                        resolve({ error: error });
+                        // Log stack trace for rejected promises.
+                        if (error.message) {
+                            console.error(error)
+                        }
+                        resolve({ error: error.toString() });
                     }
                 });
             }
diff --git 
a/tests/src/test/scala/runtime/actionContainers/NodeJs8ActionContainerTests.scala
 
b/tests/src/test/scala/runtime/actionContainers/NodeJs8ActionContainerTests.scala
index 61fa8df..c487b89 100644
--- 
a/tests/src/test/scala/runtime/actionContainers/NodeJs8ActionContainerTests.scala
+++ 
b/tests/src/test/scala/runtime/actionContainers/NodeJs8ActionContainerTests.scala
@@ -52,4 +52,44 @@ class NodeJs8ActionContainerTests extends 
NodeJsNonConcurrentTests {
     }
   }
 
+  it should "support errors thrown from async functions" in {
+    withNodeJsContainer { c =>
+      val code = """
+                   | async function main() {
+                   |   return a.b.c
+                   | }
+                 """.stripMargin;
+
+      val (initCode, _) = c.init(initPayload(code))
+      initCode should be(200)
+
+      val (runCode, runRes) = c.run(runPayload(JsObject()))
+      runCode should be(200) // action writer returning an error is OK
+
+      runRes shouldBe defined
+      runRes.get.fields.get("error") shouldBe defined
+      runRes.get.fields("error").toString.toLowerCase should 
include("referenceerror: a is not defined")
+    }
+  }
+
+  it should "support user thrown errors from async functions" in {
+    withNodeJsContainer { c =>
+      val code = """
+                   | async function main() {
+                   |   throw new Error('app error')
+                   | }
+                 """.stripMargin;
+
+      val (initCode, _) = c.init(initPayload(code))
+      initCode should be(200)
+
+      val (runCode, runRes) = c.run(runPayload(JsObject()))
+      runCode should be(200) // action writer returning an error is OK
+
+      runRes shouldBe defined
+      runRes.get.fields.get("error") shouldBe defined
+      runRes.get.fields("error").toString.toLowerCase should include("error: 
app error")
+    }
+  }
+
 }


 

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to