{"record":{"id":"21b2af44b65f9b6e","repo":"henrygd/beszel","slug":"new-request-w","errorCode":null,"errorMessage":"new request: %w","messagePattern":"new request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agent/tools/fetchsmartctl/main.go","lineNumber":54,"sourceCode":"\t\t}\n\t}\n\n\tif err := downloadFile(*url, *out, *sha); err != nil {\n\t\tfatalf(\"download failed: %v\", err)\n\t}\n}\n\nfunc downloadFile(url, dest, shaHex string) error {\n\t// Prepare destination\n\tif err := os.MkdirAll(filepath.Dir(dest), 0o755); err != nil {\n\t\treturn fmt.Errorf(\"create dir: %w\", err)\n\t}\n\n\t// HTTP client\n\tclient := &http.Client{Timeout: 60 * time.Second}\n\treq, err := http.NewRequest(http.MethodGet, url, nil)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"new request: %w\", err)\n\t}\n\treq.Header.Set(\"User-Agent\", \"beszel-fetchsmartctl/1.0\")\n\n\tresp, err := client.Do(req)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"http get: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\tif resp.StatusCode < 200 || resp.StatusCode >= 300 {\n\t\treturn fmt.Errorf(\"unexpected HTTP status: %s\", resp.Status)\n\t}\n\n\ttmp := dest + \".tmp\"\n\tf, err := os.OpenFile(tmp, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0o644)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"open tmp: %w\", err)\n\t}","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/henrygd/beszel/blob/b38fb7dafa60812cc22e6a84ce313e94f1ce0a32/agent/tools/fetchsmartctl/main.go#L36-L72","documentation":"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.","triggerScenarios":"Running fetchsmartctl with an invalid or empty URL argument so url.Parse fails before any network activity.","commonSituations":"Missing CLI flag leaving an empty URL; URL containing spaces or unescaped characters; copy-paste errors in build scripts or Makefiles.","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"],"exampleFix":"// before\nreq, err := http.NewRequest(http.MethodGet, url, nil)\nif err != nil {\n\treturn fmt.Errorf(\"new request: %w\", err)\n}\n// after\nif u, perr := url.Parse(url); perr != nil || u.Scheme == \"\" || u.Host == \"\" {\n\treturn fmt.Errorf(\"invalid download URL %q\", url)\n}\nreq, err := http.NewRequest(http.MethodGet, url, nil)","handlingStrategy":"validation","validationCode":"u, err := url.Parse(downloadURL)\nif err != nil || u.Scheme == \"\" || u.Host == \"\" {\n\treturn fmt.Errorf(\"invalid URL %q\", downloadURL)\n}","typeGuard":"func isValidURL(s string) bool {\n\tu, err := url.Parse(s)\n\treturn err == nil && (u.Scheme == \"http\" || u.Scheme == \"https\") && u.Host != \"\"\n}","tryCatchPattern":"if err := downloadFile(url, dest, sha); err != nil {\n\tif strings.HasPrefix(err.Error(), \"new request:\") {\n\t\tfmt.Printf(\"bad URL %q: %v\\n\", url, err)\n\t\tos.Exit(2)\n\t}\n\treturn err\n}","preventionTips":["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"],"tags":["http","url","build-tool"],"backgroundTag":"invalid-url","analyzedSha":"b38fb7dafa60812cc22e6a84ce313e94f1ce0a32","analyzedAt":"2026-08-31T15:10:10.149Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}