Skip to content

Commit

Permalink
Improve error message for the most common user error
Browse files Browse the repository at this point in the history
  • Loading branch information
mnapoli committed Sep 8, 2021
1 parent ae157f3 commit 39e3820
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/constructs/aws/Queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 39e3820

Please sign in to comment.