{"record":{"id":"d3ab6fd53b3c616b","repo":"golang/go","slug":"path-is-not-absolute","errorCode":null,"errorMessage":"path is not absolute","messagePattern":"path is not absolute","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/web/url.go","lineNumber":17,"sourceCode":"// Copyright 2019 The Go Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style\n// 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))","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/web/url.go#L1-L35","documentation":"urlToFilePath converts a file:// URL to a filesystem path and requires the path to be absolute (errNotAbsolute). A relative path in a file URL is rejected because module fetching needs an unambiguous absolute location.","triggerScenarios":"A file:// URL with a relative path (e.g. file:lib or file://./rel) is passed into module resolution.","commonSituations":"Misconstructed file:// URLs in replace directives or tooling that builds URLs from non-absolute paths.","solutions":["Use an absolute path in the file:// URL.","Prefer a plain filesystem path in a replace directive instead of a file:// URL."],"exampleFix":"// before\n// replace example.com/lib => file:./lib\n\n// after\n// replace example.com/lib => /home/me/proj/lib","handlingStrategy":"validation","validationCode":"// Ensure file:// URLs point at absolute paths.\nfunc absoluteFileURL(s string) error {\n    u, err := url.Parse(s)\n    if err != nil { return err }\n    if u.Scheme == \"file\" && !filepath.IsAbs(u.Path) {\n        return errors.New(\"file URL path must be absolute\")\n    }\n    return nil\n}","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Use plain filesystem paths (not file:// URLs) in replace directives.","Resolve relative paths to absolute before constructing file:// URLs."],"tags":["web","file-url","validation","replace-directive"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}