Skip to content

fix(http): getMeta returns no metadata for a missing key - #866

Closed
superbot-helper wants to merge 1 commit into
unjs:mainfrom
superbot-helper:fix/http-getmeta-404
Closed

superbot-helper wants to merge 1 commit into
unjs:mainfrom
superbot-helper:fix/http-getmeta-404

Conversation

@superbot-helper

@superbot-helper superbot-helper commented Nov 3, 2026 •

Copy link
Copy Markdown

What happens

The http driver's hasItem, getItem and getItemRaw all catch a failed request and answer false or null. getMeta did not, so a key that simply does not exist rejected with an exception where its siblings answered.

Against a real createStorageHandler behind a node server, through the published [email protected]:

getItem("nope")   -> null
hasItem("nope")   -> false
getKeys()         -> ["doc"]
getMeta("nope")   -> THREW FetchError 404 [HEAD] ".../nope": 404 Not Found

memory getMeta("nope") -> {} (null prototype)

Driver.getMeta is typed StorageMeta | null (src/types.ts:132) and core merges a null into an empty object (src/storage.ts:443-446), so throwing was never part of the contract. Any caller that probes metadata before reading — revalidation, a conditional fetch — gets an exception instead of "no metadata".

The change

Reuses catchFetchError, the same helper the three sibling methods one screen above already use, and returns null when there is no response. Core turns that into {} exactly as it does for memory and fs. One call site, no new dependency, no change to any other method.

Verification

Patched build against the published package: getMeta("nope") now answers {}, matching memory. Restoring the unpatched driver file reproduces the 404 exception. Nothing else in the driver changed.

Not a duplicate

Six open pull requests mention getMeta (#772, #587, #363, #276, #807, #859) and none touches the http driver's metadata path; 41 open pull requests mention the http driver and none is this. Searched by symptom across issues and pull requests, open and closed.

Scope

The http driver only. The same 404 tolerance question for the Azure drivers is a separate surface and is not touched here.

Summary by CodeRabbit

  • Bug Fixes
    • Metadata lookups for missing keys now return no result instead of an error. Other fetch errors continue to be reported.

The http driver's hasItem, getItem and getItemRaw all catch a failed request
and answer false or null. getMeta did not, so a key that simply does not exist
rejected with FetchError 404 where the siblings answered. `Driver.getMeta` is
typed `StorageMeta | null` and core merges a null, so the exception was never
part of the contract.

Reuses catchFetchError and returns null, which core turns into {} the same way
it does for memory and fs.
@superbot-helper
superbot-helper requested a review from pi0 as a code owner November 3, 2026 10:43
@vercel

vercel Bot commented Nov 3, 2026

Copy link
Copy Markdown

@superbot-helper is attempting to deploy a commit to the unjs Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

The HTTP driver's getMeta method now handles a 404 from its HEAD request with catchFetchError and returns null when no response is available. Other fetch errors continue to propagate, and successful responses still produce metadata.

Changes: HTTP metadata lookup

Layer / File(s) Summary
Handle missing metadata
src/drivers/http.ts
getMeta applies catchFetchError to the HEAD request and returns null when no response is available.

Estimated code review effort: 2 (Simple) | ~5 minutes

Change: Bug fix

Merge Risk: Minimal · up to 4d657

Missing-key HTTP metadata requests now return empty metadata instead of throwing a 404, while other failures retain their existing behavior. No actionable merge-blocking risk was identified.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix(http): getMeta returns no metadata for a missing key" matches the single change in the changeset. The raw summary says getMeta now applies the shared 404 handler to its HEAD request and…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix(http): getMeta returns no metadata for a missing key" matches the single change in the changeset. The raw summary says getMeta now applies the shared 404 handler to its HEAD request and returns null when the key is missing. The objectives describe the same fix, with core converting null to {} as memory and fs do. The title is specific and names the affected driver and method.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 1 files.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: db02c4aa-3040-445c-be1e-33b338d3273c
Commits

Reviewing files that changed from the base of the PR and between 5781aae and 4d657b7.

Files selected for processing: 1
  • src/drivers/http.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

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