From 39e3820e8c54fd79beeb5aa87441df6e12bb37f7 Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Wed, 8 Sep 2021 14:49:34 +0200 Subject: [PATCH] Improve error message for the most common user error --- src/constructs/aws/Queue.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/constructs/aws/Queue.ts b/src/constructs/aws/Queue.ts index 3d3c8385..8f75c149 100644 --- a/src/constructs/aws/Queue.ts +++ b/src/constructs/aws/Queue.ts @@ -17,6 +17,7 @@ import { pollMessages, retryMessages } from "./queue/sqs"; import { sleep } from "../../utils/sleep"; import { PolicyStatement } from "../../CloudFormation"; import type { CliOptions } from "../../types/serverless"; +import ServerlessError from "../../utils/error"; const QUEUE_DEFINITION = { type: "object", @@ -109,6 +110,16 @@ export class Queue extends AwsConstruct { ) { super(scope, id); + // This should be covered by the schema validation, but until it is enforced by default + // this is a very common error for users + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition + if (configuration.worker === undefined) { + throw new ServerlessError( + `Invalid configuration in 'constructs.${this.id}': no 'worker' defined. Queue constructs require a 'worker' function to be defined.`, + "LIFT_INVALID_CONSTRUCT_CONFIGURATION" + ); + } + // The default function timeout is 6 seconds in the Serverless Framework const functionTimeout = configuration.worker.timeout ?? 6;