Skip to content

Commit 247b649

Browse files
authored
Merge pull request #196 from elastic-coders/handle-entry-detection-for-malformed-handlers
Ignore handlers that do not follow a path pattern
2 parents cf51110 + 5916a90 commit 247b649

File tree

2 files changed

+42
-36
lines changed

2 files changed

+42
-36
lines changed

lib/validate.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,16 @@ module.exports = {
4848
return path.extname(_.first(sortedFiles));
4949
}
5050

51-
const getEntryForFunction = serverlessFunction => {
51+
const getEntryForFunction = (name, serverlessFunction) => {
5252
const handler = serverlessFunction.handler;
53-
const handlerFile = /(.*)\..*?$/.exec(handler)[1];
54-
53+
// Check if handler is a well-formed path based handler.
54+
const handlerEntry = /(.*)\..*?$/.exec(handler);
55+
if (!handlerEntry) {
56+
_.get(this.serverless, 'service.provider.name') !== 'google' &&
57+
this.serverless.cli.log(`\nWARNING: Entry for ${name}@${handler} could not be retrieved.\nPlease check your service config if you want to use lib.entries.`);
58+
return {};
59+
}
60+
const handlerFile = handlerEntry[1];
5561
const ext = getEntryExtension(handlerFile);
5662

5763
// Create a valid entry key
@@ -70,12 +76,12 @@ module.exports = {
7076
const entries = {};
7177
const functions = this.serverless.service.getAllFunctions();
7278
if (this.options.function) {
73-
const serverlessFunction = this.serverless.service.getFunction(this.options.function);
74-
const entry = getEntryForFunction(serverlessFunction);
79+
const serverlessFunction = this.serverless.service.getFunction(this.options.function);
80+
const entry = getEntryForFunction.call(this, this.options.function, serverlessFunction);
7581
_.merge(entries, entry);
7682
} else {
77-
_.forEach(functions, func => {
78-
const entry = getEntryForFunction(this.serverless.service.getFunction(func));
83+
_.forEach(functions, (func, index) => {
84+
const entry = getEntryForFunction.call(this, functions[index], this.serverless.service.getFunction(func));
7985
_.merge(entries, entry);
8086
});
8187
}

package-lock.json

Lines changed: 29 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)