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

Fix error log output #5378

Merged
merged 2 commits into from
Dec 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

throw new Error('Initialization failed');
4 changes: 2 additions & 2 deletions lib/plugins/aws/invokeLocal/index.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const validate = require('../lib/validate');
const chalk = require('chalk'); const chalk = require('chalk');
const stdin = require('get-stdin'); const stdin = require('get-stdin');
const spawn = require('child_process').spawn; const spawn = require('child_process').spawn;

const inspect = require('util').inspect;


class AwsInvokeLocal { class AwsInvokeLocal {
constructor(serverless, options) { constructor(serverless, options) {
Expand Down Expand Up @@ -268,7 +268,7 @@ class AwsInvokeLocal {
); );
lambda = handlersContainer[handlerName]; lambda = handlersContainer[handlerName];
} catch (error) { } catch (error) {
this.serverless.cli.consoleLog(chalk.red(JSON.stringify(error, null, 4))); this.serverless.cli.consoleLog(chalk.red(inspect(error)));
throw new Error(`Exception encountered when loading ${pathToHandler}`); throw new Error(`Exception encountered when loading ${pathToHandler}`);
} }


Expand Down
14 changes: 14 additions & 0 deletions lib/plugins/aws/invokeLocal/index.test.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -503,6 +503,20 @@ describe('AwsInvokeLocal', () => {
expect(serverless.cli.consoleLog.lastCall.args[0]).to.contain('"errorType": "Error"'); expect(serverless.cli.consoleLog.lastCall.args[0]).to.contain('"errorType": "Error"');
}); });


it('should log Error object if handler crashes at initialization', () => {
awsInvokeLocal.serverless.config.servicePath = __dirname;

try {
awsInvokeLocal.invokeLocalNodeJs('fixture/handlerWithInitializationError', 'withError');
} catch (error) {
if (!error.message.startsWith('Exception encountered when loading')) {
throw error;
}
}

expect(serverless.cli.consoleLog.lastCall.args[0]).to.contain('Initialization failed');
});

it('should log error when called back', () => { it('should log error when called back', () => {
awsInvokeLocal.serverless.config.servicePath = __dirname; awsInvokeLocal.serverless.config.servicePath = __dirname;


Expand Down