henrygd/beszel · error
new request: %w
Error message
new request: %w
What it means
Thrown by downloadFile when http.NewRequestWithContext/NewRequest fails to construct the GET request, meaning the URL string could not be parsed. Because the URL comes from the tool's configuration/args, this is almost always a malformed or empty URL supplied at invocation time.
Source
Thrown at agent/tools/fetchsmartctl/main.go:54
}
}
if err := downloadFile(*url, *out, *sha); err != nil {
fatalf("download failed: %v", err)
}
}
func downloadFile(url, dest, shaHex string) error {
// Prepare destination
if err := os.MkdirAll(filepath.Dir(dest), 0o755); err != nil {
return fmt.Errorf("create dir: %w", err)
}
// HTTP client
client := &http.Client{Timeout: 60 * time.Second}
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return fmt.Errorf("new request: %w", err)
}
req.Header.Set("User-Agent", "beszel-fetchsmartctl/1.0")
resp, err := client.Do(req)
if err != nil {
return fmt.Errorf("http get: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return fmt.Errorf("unexpected HTTP status: %s", resp.Status)
}
tmp := dest + ".tmp"
f, err := os.OpenFile(tmp, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0o644)
if err != nil {
return fmt.Errorf("open tmp: %w", err)
}View on GitHub (pinned to b38fb7dafa)
Solutions
- Print and inspect the URL argument passed to the tool; fix malformed characters or missing scheme
- Quote the URL in shell scripts so spaces/special chars aren't split
- Ensure the flag providing the URL is actually set in the build script
- Validate with a quick curl of the same URL
Example fix
// before
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return fmt.Errorf("new request: %w", err)
}
// after
if u, perr := url.Parse(url); perr != nil || u.Scheme == "" || u.Host == "" {
return fmt.Errorf("invalid download URL %q", url)
}
req, err := http.NewRequest(http.MethodGet, url, nil) Defensive patterns
Strategy: validation
Validate before calling
u, err := url.Parse(downloadURL)
if err != nil || u.Scheme == "" || u.Host == "" {
return fmt.Errorf("invalid URL %q", downloadURL)
} Type guard
func isValidURL(s string) bool {
u, err := url.Parse(s)
return err == nil && (u.Scheme == "http" || u.Scheme == "https") && u.Host != ""
} Try / catch
if err := downloadFile(url, dest, sha); err != nil {
if strings.HasPrefix(err.Error(), "new request:") {
fmt.Printf("bad URL %q: %v\n", url, err)
os.Exit(2)
}
return err
} Prevention
- Always include https:// scheme in download URLs
- Quote URLs in shell scripts to prevent word-splitting
- Validate URL arguments before invoking the tool
- Keep download URLs in versioned build config, not inline shell
When it happens
Trigger: Running fetchsmartctl with an invalid or empty URL argument so url.Parse fails before any network activity.
Common situations: Missing CLI flag leaving an empty URL; URL containing spaces or unescaped characters; copy-paste errors in build scripts or Makefiles.
Related errors
- unexpected HTTP status: %s
- container inspect request failed: %s
- docker version request failed: %s
- container info request failed: %s: %s
- logs request failed: %s: %s
AI-assisted analysis of henrygd/beszel@b38fb7dafa (2026-08-31).
Data as JSON: /api/errors/21b2af44b65f9b6e.
Report an issue: GitHub.