{"record":{"id":"cf4c60621871af17","repo":"golang/go","slug":"non-file-url","errorCode":null,"errorMessage":"non-file URL","messagePattern":"non-file URL","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/web/url.go","lineNumber":21,"sourceCode":"// license that can be found in the LICENSE file.\n\npackage web\n\nimport (\n\t\"errors\"\n\t\"net/url\"\n\t\"path/filepath\"\n\t\"strings\"\n)\n\n// TODO(golang.org/issue/32456): If accepted, move these functions into the\n// net/url package.\n\nvar errNotAbsolute = errors.New(\"path is not absolute\")\n\nfunc urlToFilePath(u *url.URL) (string, error) {\n\tif u.Scheme != \"file\" {\n\t\treturn \"\", errors.New(\"non-file URL\")\n\t}\n\n\tcheckAbs := func(path string) (string, error) {\n\t\tif !filepath.IsAbs(path) {\n\t\t\treturn \"\", errNotAbsolute\n\t\t}\n\t\treturn path, nil\n\t}\n\n\tif u.Path == \"\" {\n\t\tif u.Host != \"\" || u.Opaque == \"\" {\n\t\t\treturn \"\", errors.New(\"file URL missing path\")\n\t\t}\n\t\treturn checkAbs(filepath.FromSlash(u.Opaque))\n\t}\n\n\tpath, err := convertFileURLPath(u.Host, u.Path)\n\tif err != nil {","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/web/url.go#L3-L39","documentation":"Thrown by urlToFilePath in cmd/go/internal/web when a *url.URL passed in does not use the \"file\" scheme. The web package converts between file:// URLs and OS file paths for the go command (module proxy caches, vendored downloads, -overlay file lists), and it will only ever reverse a file: URL into a local path — http, https, ftp, or any other scheme is rejected at the very first guard. The error is a hard precondition, not a recoverable state.","triggerScenarios":"Calling web.URLToFilePath (or any go-command code path that feeds it) with a url.URL whose Scheme is anything other than \"file\" — e.g. an http(s) module proxy URL, an ssh URL, or a relative URL whose Scheme was left empty. Constructed manually with &url.URL{Scheme: \"https\", ...} or parsed from \"https://example.org/mod.zip\" and handed to the converter.","commonSituations":"Plugins or scripts that wrap `go mod download`, `go get`, or GOPROXY/GOMODCACHE manipulation and reuse the same URL variable for both network fetches and local file lookups. Misconfigured GOFLAGS or -modcacherw tooling that records proxy URLs where file URLs were expected. A typo when building a file:// URL by hand (forgetting the Scheme or setting it to \"https\").","solutions":["Ensure the URL passed in is built with Scheme: \"file\" — verify with `u.Scheme == \"file\"` before calling URLToFilePath.","If you have an http(s) URL, download it to a local path first and then construct a file URL from the downloaded path via web.URLFromFilePath.","Use url.Parse on a string that already starts with \"file://\" rather than assembling the URL struct field-by-field.","Audit GOFLAGS, GOPROXY, and GOPATH/module-cache handling code for places that pass proxy URLs where the converter expects file URLs."],"exampleFix":"// before\nu, _ := url.Parse(\"https://proxy.golang.org/m.zip\")\npath, err := web.URLToFilePath(u) // -> \"non-file URL\"\n\n// after\nu, _ := url.Parse(\"file:///tmp/cache/m.zip\")\npath, err := web.URLToFilePath(u)","handlingStrategy":"validation","validationCode":"// before calling web.URLToFilePath:\nif u.Scheme != \"file\" {\n    return fmt.Errorf(\"expected file URL, got %q\", u.Scheme)\n}\npath, err := web.URLToFilePath(u)","typeGuard":"func isFileURL(u *url.URL) bool { return u != nil && u.Scheme == \"file\" }","tryCatchPattern":null,"preventionTips":["Centralize file-URL construction in one helper that always sets Scheme to \"file\".","Prefer web.URLFromFilePath(absPath) over hand-building url.URL structs.","Never reuse the same URL variable for proxy URLs and file URLs."],"tags":["go-toolchain","url","file-url","validation"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}