golang/go · error
invalid %s path: %v
Error message
invalid %s path: %v
What it means
Thrown by parsePathVersionOptional (used by `go work edit -dropuse`/`-replace`) when the module-path portion of an argument fails module.CheckImportPath and the caller did not allow directory paths (or the path is not a directory-shaped path). It surfaces the underlying import-path validation error.
Source
Thrown at src/cmd/go/internal/workcmd/edit.go:297
func allowedVersionArg(arg string) bool {
return !modfile.MustQuote(arg)
}
// parsePathVersionOptional parses path[@version], using adj to
// describe any errors.
func parsePathVersionOptional(adj, arg string, allowDirPath bool) (path, version string, err error) {
before, after, found, err := modload.ParsePathVersion(arg)
if err != nil {
return "", "", err
}
if !found {
path = arg
} else {
path, version = strings.TrimSpace(before), strings.TrimSpace(after)
}
if err := module.CheckImportPath(path); err != nil {
if !allowDirPath || !modfile.IsDirectoryPath(path) {
return path, version, fmt.Errorf("invalid %s path: %v", adj, err)
}
}
if path != arg && !allowedVersionArg(version) {
return path, version, fmt.Errorf("invalid %s version: %q", adj, version)
}
return path, version, nil
}
// flagEditworkReplace implements the -replace flag.
func flagEditworkReplace(arg string) {
before, after, found := strings.Cut(arg, "=")
if !found {
base.Fatalf("go: -replace=%s: need old[@v]=new[@w] (missing =)", arg)
}
old, new := strings.TrimSpace(before), strings.TrimSpace(after)
if strings.HasPrefix(new, ">") {
base.Fatalf("go: -replace=%s: separator between old and new is =, not =>", arg)
}View on GitHub (pinned to b6b368adc5)
Solutions
- Correct the module path to match Go import-path rules (lowercase, no spaces, dot-separated).
- For a local directory, ensure the path looks like a directory path (modfile.IsDirectoryPath) and the command allows it.
- Strip a leading scheme/host if you pasted a full URL: use the import path component only.
- Validate first: `go list -m <path>`.
Example fix
# before // go work edit -dropuse GitHub.com/User/Mod # after // go work edit -dropuse github.com/user/mod
Defensive patterns
Strategy: validation
Validate before calling
// Validate a module path before passing to `go work edit`
if err := module.CheckImportPath(path); err != nil {
log.Fatalf("invalid module path %q: %v", path, err)
} Prevention
- Use lowercase, dot-separated module paths.
- Strip URL schemes/hosts from pasted URLs.
- Test paths with `go list -m` first.
When it happens
Trigger: Run `go work edit -dropuse Bad-Path` or `-replace Bad-Path=foo@v1` where the path violates Go import-path rules (uppercase letters, spaces, leading dots, invalid characters, empty segments). CheckImportPath returns an error and parsePathVersionOptional wraps it.
Common situations: Typo in a module path; passing a local Windows path with backslashes; using a capitalized or spaced repository name; copy-pasting a URL instead of a module path; trailing slashes or double slashes.
Related errors
- invalid %s version: %q
- %v is not a regular file
- non-file URL
- file URL missing path
- file URL encodes volume in host field: too few slashes?
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/eb359f6d5be64dd5.
Report an issue: GitHub.