Skip to content

Enhance wrapAsAsync to support callbacks#218

Open
czirker wants to merge 1 commit intomasterfrom
czirker-patch-1
Open

Enhance wrapAsAsync to support callbacks#218
czirker wants to merge 1 commit intomasterfrom
czirker-patch-1

Conversation

@czirker
Copy link
Copy Markdown
Contributor

@czirker czirker commented Mar 30, 2026

Added support for callback-style Lambda handlers in wrapAsAsync.


Note

Low Risk
Low risk, small change isolated to wrapAsAsync to support legacy callback invocation. Main risk is subtle behavior differences if a runtime provides a callback while callers expect a Promise.

Overview
Updates wrapAsAsync to accept an optional callback argument and, when present, bypass Promise-wrapping and directly invoke the underlying handler with that callback.

When no callback is provided, it keeps the existing behavior of converting callback-style handlers into a Promise-returning async handler.

Written by Cursor Bugbot for commit bcbce08. This will update automatically on new commits. Configure here.

Added support for callback-style Lambda handlers in wrapAsAsync.
@ch-snyk-sa
Copy link
Copy Markdown

ch-snyk-sa commented Mar 30, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

// Support old runtimes that only accept callbacks and not async functions
if (callback != null){
return handler(event, context, callback)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Async wrapper resolves prematurely on old runtimes

High Severity

When an old Lambda runtime provides a callback, the callback != null branch does return handler(event, context, callback). Since the wrapped handlers (in cron.js, fanout.js, resource.js, test.js) are callback-style and return undefined synchronously, and the wrapper is async, the implicit Promise immediately resolves with undefined. The Lambda runtime uses this resolved Promise as the response, completing the invocation before the handler's actual work finishes and the callback is called. This causes all wrapped handlers to return undefined on Node.js 18–22 runtimes.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants