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
File filter...
Filter file types
Jump to file or symbol
Failed to load files and symbols.
+19 −2
Diff settings

Always

Just for now

@@ -0,0 +1,3 @@
'use strict';

throw new Error('Initialization failed');
@@ -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) {
@@ -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}`);
} }


@@ -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;


ProTip! Use n and p to navigate between commits in a pull request.