Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stack trace to aws/invokeLocal errors #5835

Merged
merged 2 commits into from Feb 14, 2019

Conversation

Projects
4 participants
@Xenonym
Copy link
Contributor

Xenonym commented Feb 14, 2019

What did you implement:

Closes #5834.

How did you implement it:

I added err.stack to the error result that aws/invokeLocal/index.js#handleError returns to include a stack trace in the error message.

How can we verify it:

  1. serverless create --template aws-nodejs
  2. Add the following handler:
module.exports.testError = async function(data, context) {
    throw new Error('testError');
    return 'unreachable';
};
  1. serverless invoke local -s aws-nodejs -l --function testError should error with a stack trace:
{
    "errorMessage": "testError",
    "errorType": "Error",
    "stackTrace": [
        "Error: testError",
        "    at module.exports.testError (C:\\Users\\user\\Desktop\\test_serverless\\handler.js:17:11)",
        "    at Promise (C:\\Users\\user\\Documents\\GitHub\\externalProjects\\serverless\\lib\\plugins\\aws\\invokeLocal\\index.js:409:30)",
        "    at new Promise (<anonymous>)",
        "    at AwsInvokeLocal.invokeLocalNodeJs (C:\\Users\\user\\Documents\\GitHub\\externalProjects\\serverless\\lib\\plugins\\aws\\invokeLocal\\index.js:363:12)",
        "    at AwsInvokeLocal.invokeLocal (C:\\Users\\user\\Documents\\GitHub\\externalProjects\\serverless\\lib\\plugins\\aws\\invokeLocal\\index.js:137:19)",
        "    at AwsInvokeLocal.tryCatcher (C:\\Users\\user\\Documents\\GitHub\\externalProjects\\serverless\\node_modules\\bluebird\\js\\release\\util.js:16:23)",
        "    at Promise._settlePromiseFromHandler (C:\\Users\\user\\Documents\\GitHub\\externalProjects\\serverless\\node_modules\\bluebird\\js\\release\\promise.js:512:31)",
        "    at Promise._settlePromise (C:\\Users\\user\\Documents\\GitHub\\externalProjects\\serverless\\node_modules\\bluebird\\js\\release\\promise.js:569:18)",
        "    at Promise._settlePromiseCtx (C:\\Users\\user\\Documents\\GitHub\\externalProjects\\serverless\\node_modules\\bluebird\\js\\release\\promise.js:606:10)",
        "    at _drainQueueStep (C:\\Users\\user\\Documents\\GitHub\\externalProjects\\serverless\\node_modules\\bluebird\\js\\release\\async.js:142:12)",
        "    at _drainQueue (C:\\Users\\user\\Documents\\GitHub\\externalProjects\\serverless\\node_modules\\bluebird\\js\\release\\async.js:131:9)",
        "    at Async._drainQueues (C:\\Users\\user\\Documents\\GitHub\\externalProjects\\serverless\\node_modules\\bluebird\\js\\release\\async.js:147:5)",
        "    at Immediate.Async.drainQueues [as _onImmediate] (C:\\Users\\user\\Documents\\GitHub\\externalProjects\\serverless\\node_modules\\bluebird\\js\\release\\async.js:17:14)",
        "    at runCallback (timers.js:810:20)",
        "    at tryOnImmediate (timers.js:768:5)",
        "    at processImmediate [as _immediateCallback] (timers.js:745:5)"
    ]
}

Todos:

  • Write tests
  • Write documentation
  • Fix linting errors
  • Make sure code coverage hasn't dropped
  • Provide verification config / commands / resources
  • Enable "Allow edits from maintainers" for this PR
  • Update the messages below

Is this ready for review?: YES
Is it a breaking change?: NO

@pmuens pmuens self-assigned this Feb 14, 2019

@pmuens pmuens added the pr/in-review label Feb 14, 2019

@pmuens pmuens added this to In progress in Serverless via automation Feb 14, 2019

Serverless automation moved this from In progress to Reviewer approved Feb 14, 2019

@pmuens
Copy link
Member

pmuens left a comment

Just tested it and it works fine!

Thanks for implementing this @Xenonym 👌 💯

@pmuens pmuens dismissed their stale review via 0fd6733 Feb 14, 2019

Serverless automation moved this from Reviewer approved to Needs review Feb 14, 2019

@pmuens

pmuens approved these changes Feb 14, 2019

Copy link
Member

pmuens left a comment

Just pushed a minor fix after reading @dschep comment where I reworked the error tests so that they test the actual properties of the error log message in a more explicit way.

Will merge once Travis is happy... :shipit:

Serverless automation moved this from Needs review to Reviewer approved Feb 14, 2019

@pmuens pmuens merged commit ad02e0f into serverless:master Feb 14, 2019

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

Serverless automation moved this from Reviewer approved to Done Feb 14, 2019

@pmuens pmuens added this to the 1.38.0 milestone Feb 14, 2019

@Xenonym Xenonym deleted the Xenonym:enhancement/aws-invokeLocal-stackTrace branch Feb 14, 2019

@thaddeusmt

This comment has been minimized.

Copy link

thaddeusmt commented Feb 14, 2019

Thanks for the quick work on this, it'll be super helpful doing local testing for AWS functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.