edit-icon download-icon

Error message

Last Updated: Mar 29, 2018

Two types of errors may occur during a function operation:

  • Handled error: an error proactively captured by the user function and returned through callback.
  • Unhandled error: an error that is not captured by the user function, such as a syntax error, request timeout, out of memory and so on.

Function Compute encodes errors into JSON strings and returns them to the caller.

Handled error

When user function captures an error and returns it through callback(err), if the err parameter is an object whose type is Error, the stack trace is also returned.

  1. // User function.
  2. exports.handler = function(event, context, callback) {
  3. var error = new Error("something is wrong");
  4. callback(error);
  5. };
  6. // Function response.
  7. {
  8. "errorMessage": "something is wrong",
  9. "errorType": "Error",
  10. "stackTrace": [
  11. "export.handler (/var/task/index.js.3:16)"
  12. ]
  13. }

If the callback parameter is a non-error object, the stack trace is not returned.

  1. // User function.
  2. exports.handler = function(event, context, callback) {
  3. callback("something is wrong");
  4. };
  5. // Function response.
  6. {
  7. "errorMessage": "something is wrong"
  8. }

Unhandled error

When the user function does not capture any errors, Function Compute tries to capture errors as far as possible and returns the detailed information. If an error fails to be captured by the system, for example, a user function crashes unexpectedly and exits during execution, the system returns a general error.

Typical error scenarios

Error type Scenario Error information
Handled An error returned through callback(err), in which the type of err is error. {“errorMessage”: “oops”, “errorType”: “Error”, “stackTrace”: [“exports.handler (/var/task/index.js:5:14)”]}
Handled An error returned through callback(obj), in which obj is a non-error object. {“errorMessage”: “oops”}
Unhandled The function reference does not exist. {“errorMessage”: “Cannot find module ‘/code/X.js”}
Unhandled The specified handler function does not exist. {“errorMessage”: “Handler ‘X’ missing on module ‘Y’”}
Unhandled The function execution times out. {“errorMessage”: “Task timed out after X seconds”}
Unhandled An error related to and handled by another user program. {“errorMessage”: “Process exited unexpectedly before completing request”}
Thank you! We've received your feedback.