Skip to content

Conversation

@nicholasgriffintn
Copy link
Member

@nicholasgriffintn nicholasgriffintn commented Oct 6, 2025

This PR introduces a new flag, strictReturn, which enforces explicit return values from message handlers in order to prevent ambiguous acknowledgment behavior. When enabled, the consumer requires each handler (handleMessage or handleMessageBatch) to explicitly return one of the following:

  • A Message (or array of Messages) → acknowledge and delete the message(s)
  • undefined → leave the message(s) on the queue (nack)

Returning null or omitting a return (i.e., void) is no longer permitted under strictReturn.

Motivation

Historically, handlers could return void or null, which SQS Consumer treated as “do nothing.”
This behavior often led to accidental message retention, especially when developers forgot to return a value.

The strictReturn flag:

  • Makes handler intent explicit
  • Prevents silent failures caused by missing return statements
  • Paves the way for strictReturn to become the default behavior in a future major release

This aligns with ongoing deprecation of void/null returns (see #598

Behavior

Return value strictReturn: false (default) strictReturn: true
Message ✅ Acknowledge ✅ Acknowledge
undefined ✅ Leave on queue ✅ Leave on queue
null ⚠️ Logs deprecation warning ❌ Throws error

@nicholasgriffintn nicholasgriffintn requested review from a team as code owners October 6, 2025 02:17
@nicholasgriffintn nicholasgriffintn marked this pull request as draft October 6, 2025 02:17
@github-actions
Copy link

github-actions bot commented Oct 6, 2025

LCOV of commit d883f0a during Comment PR Coverage #166

Summary coverage rate:
  lines......: 97.1% (1023 of 1054 lines)
  functions..: 97.3% (36 of 37 functions)
  branches...: no data found

Files changed coverage rate:
                   |Lines       |Functions  |Branches    
  Filename         |Rate     Num|Rate    Num|Rate     Num
  =======================================================
  src/consumer.ts  | 3.0%    702| 0.0%    21|    -      0

@nicholasgriffintn nicholasgriffintn marked this pull request as ready for review October 6, 2025 02:39
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new strictReturn flag that enforces explicit return values from message handlers to prevent ambiguous acknowledgment behavior and accidental message retention.

  • Adds strictReturn option to ConsumerOptions interface with default value of false
  • Implements error throwing when strictReturn is enabled and handlers return null
  • Updates deprecation warning messages to specifically mention null instead of void

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.

File Description
src/types.ts Adds strictReturn boolean option to ConsumerOptions interface
src/consumer.ts Implements strictReturn logic with error throwing and updates deprecation messages
test/tests/consumer.test.ts Updates test descriptions and adds comprehensive test coverage for strictReturn behavior
README.md Documents the new strictReturn flag behavior

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

nicholasgriffintn and others added 2 commits October 6, 2025 03:45
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@nicholasgriffintn nicholasgriffintn merged commit 6556332 into canary Oct 14, 2025
9 checks passed
@nicholasgriffintn nicholasgriffintn deleted the strictReturn-flag branch October 14, 2025 03:21
@github-actions github-actions bot locked and limited conversation to collaborators Oct 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants