Skip to content

fix(require-fetch-try-catch): no-op false positive for await fetch inside directly-awaited async callback#47969

Merged
pelikhan merged 3 commits into
mainfrom
copilot/require-fetch-try-catch-fix-again
Jul 25, 2026
Merged

fix(require-fetch-try-catch): no-op false positive for await fetch inside directly-awaited async callback#47969
pelikhan merged 3 commits into
mainfrom
copilot/require-fetch-try-catch-fix-again

Conversation

Copilot AI commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

isInsideTryBlock stopped at every function boundary unconditionally, so await fetch inside an inline async callback was flagged even when the wrapping call was itself awaited inside a try block — meaning the rejection genuinely propagates to and is caught by the outer handler.

Live false positive: check_version_updates.cjs:92await fetch inside a withRetry(async () => {...}) callback that is awaited inside an outer try/catch.

Changes

eslint-factory/src/rules/require-fetch-try-catch.ts

  • When crossing a FunctionExpression/ArrowFunctionExpression boundary, check for the directly-awaited inline callback pattern before returning false:
    • ancestors[i-1] is a CallExpression, and
    • ancestors[i-2] is an AwaitExpression that is itself inside a try block with a handler
  • FunctionDeclaration still always stops the walk (cannot be an inline argument)
  • Updated the comment on the function boundary stop to clarify it applies to non-awaited (fire-and-forget) callbacks only

eslint-factory/src/rules/require-fetch-try-catch.test.ts

  • Added valid test cases for the directly-awaited callback pattern (arrow function, function expression, IIFE)
  • All three existing invalid cases (stored arrow, stored function expression, named function declaration + setTimeout) remain invalid
// now VALID — rejection propagates through the awaited chain to the outer catch
try {
  config = await withRetry(async () => {
    const res = await fetch(CONFIG_URL); // no longer flagged
    ...
  });
} catch (err) { ... }

// still INVALID — fire-and-forget; outer try cannot catch
try {
  const later = async () => { const r = await fetch(url); };
} catch (e) {}

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 9.98 AIC · ⌖ 8.65 AIC · ⊞ 7.1K ·
Comment /souschef to run again

…h inside directly-awaited async callback

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix false positive in require-fetch-try-catch rule fix(require-fetch-try-catch): no-op false positive for await fetch inside directly-awaited async callback Jul 25, 2026
Copilot AI requested a review from pelikhan July 25, 2026 09:53
@pelikhan
pelikhan marked this pull request as ready for review July 25, 2026 09:53
Copilot AI review requested due to automatic review settings July 25, 2026 09:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Refines the fetch safety rule to recognize awaited inline callbacks within try/catch.

Changes:

  • Detects directly awaited callback wrappers and IIFEs.
  • Adds valid cases for the new behavior.
  • Preserves existing invalid nested-function cases.
Show a summary per file
File Description
eslint-factory/src/rules/require-fetch-try-catch.ts Adds awaited-callback boundary handling.
eslint-factory/src/rules/require-fetch-try-catch.test.ts Adds valid callback and IIFE tests.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Medium

Comment on lines +84 to +85
ancestors[i - 1].type === AST_NODE_TYPES.CallExpression &&
ancestors[i - 2].type === AST_NODE_TYPES.AwaitExpression
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot run pr-finisherskill

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot please run the pr-finisher skill, make sure the branch is up to date, and address any remaining review feedback or follow-up comments before rerunning checks.

Run: https://github.com/github/gh-aw/actions/runs/30155206984

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 9.98 AIC · ⌖ 8.65 AIC · ⊞ 7.1K ·
Comment /souschef to run again

@pelikhan
pelikhan merged commit 662742d into main Jul 25, 2026
1 check failed
@pelikhan
pelikhan deleted the copilot/require-fetch-try-catch-fix-again branch July 25, 2026 11:01
Copilot stopped work on behalf of pelikhan due to an error July 25, 2026 11:02
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.83.3

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

Labels

None yet

Projects

None yet

4 participants