Skip to content

fix(fetch): clearer errors for non-string / host-less URLs - #43389

Open
TastyHeadphones wants to merge 1 commit into
oven-sh:mainfrom
TastyHeadphones:tiny-fetch-push
Open

TastyHeadphones wants to merge 1 commit into
oven-sh:mainfrom
TastyHeadphones:tiny-fetch-push

Conversation

@TastyHeadphones

Copy link
Copy Markdown

fetch(123), fetch(undefined), and fetch({ toString() { return "/some_path" } }) all failed with "URL must not be a blank string" even when the input wasn't blank.

When href_from_js can't build a URL, we now stringify the input (unless it's a RequestInit with a url property) so validation can say the URL is invalid. Host-less http(s)/s3 URLs get "must have a hostname" instead.

Fixes #21361

@claude claude Bot 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.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

fetch(123) and similar inputs were reported as a blank URL string.
Stringify failed coercions and use a hostname-specific error when needed.
@coderabbitai

coderabbitai Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: oven-sh/bun/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 46e06c59-50b3-45e7-92e3-aa244f2d694b

📥 Commits

Reviewing files that changed from the base of the PR and between ca41503 and 08c2ca7.

📒 Files selected for processing (2)
  • src/runtime/webcore/fetch.rs
  • test/js/web/fetch/fetch-args.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


Walkthrough

The fetch implementation now stringifies eligible non-string inputs, rejects remote URLs without hostnames, and updates the preconnect error. Tests cover invalid numeric, undefined, and relative stringified inputs.

Changes

Fetch URL validation

Layer / File(s) Summary
URL conversion and hostname validation
src/runtime/webcore/fetch.rs, test/js/web/fetch/fetch-args.test.ts
StringOrURL::from_js stringifies eligible values. fetch() and fetch.preconnect() reject remote URLs without hostnames with updated errors. Tests cover additional invalid inputs.

Suggested reviewers: robobun

Priority: ⬇️ Low

Severity of issue fixed: Low

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: clearer fetch errors for non-string and host-less URLs.
Description check ✅ Passed The description explains the fetch error-handling changes and references the linked issue. It does not include the template heading or details for how the changes were verified, but the main purpose a…
Linked Issues check ✅ Passed The changes address [#21361]. StringOrURL::from_js stringifies non-string values that are not RequestInit objects with a url property. This covers undefined, numbers, and objects whose `toStri…
Out of Scope Changes check ✅ Passed The changed source code and tests support [#21361]. The RequestInit exception preserves the existing request-init path, and the preconnect hostname validation keeps the same URL validation behavior.…

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
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.

Misleading error message "URL must not be a blank string" when URL is a non-string value which does not stringify to a fully valid URL with a hostname

1 participant