Skip to content

fix(fetch): use specific error message when URL has no hostname#26761

Open
FrankFMY wants to merge 1 commit intooven-sh:mainfrom
FrankFMY:fix-fetch-misleading-url-error
Open

fix(fetch): use specific error message when URL has no hostname#26761
FrankFMY wants to merge 1 commit intooven-sh:mainfrom
FrankFMY:fix-fetch-misleading-url-error

Conversation

@FrankFMY
Copy link

@FrankFMY FrankFMY commented Feb 5, 2026

Summary

  • When fetch() receives a URL that parses but has no hostname (e.g. fetch("/some_path"), fetch(123)), it showed "URL must not be a blank string" which is misleading
  • Added a new error message fetch_error_no_hostname = "fetch() URL must have a hostname." and use it for the hostname check
  • The original fetch_error_blank_url message is still used when the URL string is actually empty

Fixes #21361

When fetch() receives a URL that parses but has no hostname (e.g.
`fetch("/some_path")`), it previously showed the misleading message
"URL must not be a blank string". Now it shows "URL must have a
hostname" which accurately describes the problem.

Fixes oven-sh#21361
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 5, 2026

Walkthrough

A new error message constant was introduced and applied to provide a more precise error when a URL lacks a hostname during fetch preconnect operations, replacing a generic blank string error.

Changes

Cohort / File(s) Summary
Error message refinement
src/bun.js/webcore/fetch.zig
Added fetch_error_no_hostname constant and updated the hostname validation error in Bun__fetchPreconnect_ to use the more specific error message "fetch() URL must have a hostname." instead of the previously generic blank string error.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: replacing a misleading error message with a specific one when a URL lacks a hostname.
Description check ✅ Passed The description includes a clear summary of the problem and solution, with issue reference, but does not follow the template structure (missing 'What does this PR do?' and 'How did you verify your code works?' sections).
Linked Issues check ✅ Passed The PR directly addresses issue #21361 by implementing the requested change: introducing a specific error message 'fetch() URL must have a hostname' instead of the misleading 'URL must not be a blank string'.
Out of Scope Changes check ✅ Passed All changes are in-scope: a new error constant is introduced and the hostname validation error is updated to use it; no unrelated modifications are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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

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

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