fix: detect synchronous throws of falsy values in t.throwsAsync() - #3472
Open
tsushanth wants to merge 1 commit into
Open
fix: detect synchronous throws of falsy values in t.throwsAsync()#3472tsushanth wants to merge 1 commit into
tsushanth wants to merge 1 commit into
Conversation
Author
|
The |
tsushanth
force-pushed
the
fix/throwsAsync-falsy-synchronous-throw
branch
7 times, most recently
from
August 15, 2026 11:26
e7b487b to
2f06e3e
Compare
tsushanth
force-pushed
the
fix/throwsAsync-falsy-synchronous-throw
branch
8 times, most recently
from
August 23, 2026 06:01
6e3ceca to
9505187
Compare
tsushanth
force-pushed
the
fix/throwsAsync-falsy-synchronous-throw
branch
7 times, most recently
from
August 31, 2026 03:40
08b40e7 to
8d0d6a7
Compare
tsushanth
force-pushed
the
fix/throwsAsync-falsy-synchronous-throw
branch
from
September 1, 2026 13:35
8d0d6a7 to
d99ccb1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
When the function passed to
t.throwsAsync()throws a falsy value synchronously — for examplethrow 0,throw false,throw null, orthrow ""— the guard that detects the synchronous throw uses a bare truthiness check:Because
0,false,null, and""are all falsy, theif (actual)branch is skipped. The code falls through to theisPromise(retval)check (retval isundefinedsince the function threw), which also fails, so AVA ultimately reports "Function returned: undefined" instead of the correct "Function threw synchronously. Uset.throws()instead: ".Fix
Change the sentinel check to
actual !== null, matching the initial value assigned before thetry/catch.This correctly detects any synchronous throw — including falsy thrown values — without affecting the normal case where no exception is thrown (
actualremainsnull).