Skip to content

[Code Quality] Fix ESLint require-fetch-try-catch false negative for member-chained fetch #47950

Description

@github-actions

Description

The require-fetch-try-catch ESLint rule in eslint-factory/src/index.ts has a false negative: isAwaitFetchCall only matches an awaited CallExpression whose callee is the bare fetch Identifier. Any member-chained call (await fetch(url).then(...), .catch(...), .json()) has a MemberExpression callee and is silently ignored — including bare .then() chains without a rejection handler, which would crash on a network TypeError.

Grounded example: validate_secrets.cjs:65,85await fetch(...).catch(rethrowAbortError) escapes detection. While safe today (via outer try), the shape silently bypasses the rule and could mask future violations of the same pattern.

Suggested Changes

  • Extend isAwaitFetchCall to also recognize await fetch(...).method(...) chains where fetch is the root callee
  • Add logic to determine if a chain is "safe": terminal .catch(handler) or 2-arg .then(onFulfilled, onRejected) should be treated as satisfying the requirement
  • Add test cases:
    • await fetch(url).json() with no try/catch — invalid (should flag)
    • await fetch(url).catch(handler)valid (should not flag)
    • await fetch(url).then(ok, err)valid (should not flag)
    • await fetch(url).then(ok)invalid (no rejection handler)

Files Affected

  • eslint-factory/src/index.ts (require-fetch-try-catch rule, isAwaitFetchCall helper)
  • eslint-factory/src/tests/ (add test cases for chained patterns)

Success Criteria

  • await fetch(url).json() outside a try is flagged
  • await fetch(url).catch(handler) is not flagged
  • await fetch(url).then(ok, err) is not flagged
  • await fetch(url).then(ok) (1-arg) is flagged
  • Existing test cases unchanged
  • ESLint factory tests pass

Priority

Medium — prevents real-world fetch chain crashes from escaping detection

Source

Extracted from ESLint Refiner Daily Report 2026-07-25 discussion #47933

🔍 Task mining by Discussion Task Miner - Code Quality Improvement Agent · sonnet46 · 54.5 AIC · ⌖ 8.48 AIC · ⊞ 7.1K ·

  • expires on Jul 25, 2026, 11:34 PM UTC-08:00

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions