{"record":{"id":"d72521709a96a6b5","repo":"golang/go","slug":"invalid-s-version-q-d72521","errorCode":null,"errorMessage":"invalid %s version: %q","messagePattern":"invalid (.+?) version: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/workcmd/edit.go","lineNumber":301,"sourceCode":"// parsePathVersionOptional parses path[@version], using adj to\n// describe any errors.\nfunc parsePathVersionOptional(adj, arg string, allowDirPath bool) (path, version string, err error) {\n\tbefore, after, found, err := modload.ParsePathVersion(arg)\n\tif err != nil {\n\t\treturn \"\", \"\", err\n\t}\n\tif !found {\n\t\tpath = arg\n\t} else {\n\t\tpath, version = strings.TrimSpace(before), strings.TrimSpace(after)\n\t}\n\tif err := module.CheckImportPath(path); err != nil {\n\t\tif !allowDirPath || !modfile.IsDirectoryPath(path) {\n\t\t\treturn path, version, fmt.Errorf(\"invalid %s path: %v\", adj, err)\n\t\t}\n\t}\n\tif path != arg && !allowedVersionArg(version) {\n\t\treturn path, version, fmt.Errorf(\"invalid %s version: %q\", adj, version)\n\t}\n\treturn path, version, nil\n}\n\n// flagEditworkReplace implements the -replace flag.\nfunc flagEditworkReplace(arg string) {\n\tbefore, after, found := strings.Cut(arg, \"=\")\n\tif !found {\n\t\tbase.Fatalf(\"go: -replace=%s: need old[@v]=new[@w] (missing =)\", arg)\n\t}\n\told, new := strings.TrimSpace(before), strings.TrimSpace(after)\n\tif strings.HasPrefix(new, \">\") {\n\t\tbase.Fatalf(\"go: -replace=%s: separator between old and new is =, not =>\", arg)\n\t}\n\toldPath, oldVersion, err := parsePathVersionOptional(\"old\", old, false)\n\tif err != nil {\n\t\tbase.Fatalf(\"go: -replace=%s: %v\", arg, err)\n\t}","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/workcmd/edit.go#L283-L319","documentation":"Thrown by parsePathVersionOptional when the path portion differs from the raw argument (meaning a `@version` suffix was supplied) but the version token needs quoting per modfile.MustQuote (e.g. contains spaces, special characters, or otherwise would not round-trip as a single token). The version is reported verbatim.","triggerScenarios":"Run `go work edit -replace foo@bad version=bar@v1` or any work-edit argument whose `@version` portion contains characters modfile.MustQuote flags — whitespace, quotes, `@`, control chars, or a token that is not a clean version identifier.","commonSituations":"Pasting a version with a trailing comment or space (`@v1.2.3 `); using a commit hash containing unusual characters; mixing shell quoting so a space lands inside the version; targeting a version string with an embedded `@`.","solutions":["Quote the version properly in the shell and ensure it contains no spaces or special chars: `@v1.2.3`.","Use a canonical semver tag or a clean shortened commit hash.","Remove the `@version` suffix if you want the latest version resolved later.","Check modfile.MustQuote rules: avoid spaces, `\"`, `@`, and control characters."],"exampleFix":"# before\n// go work edit -replace foo@\"v1.2.3 beta\"\n\n# after\n// go work edit -replace foo@v1.2.3","handlingStrategy":"validation","validationCode":"// Ensure the version token does not require quoting\nif path != arg && modfile.MustQuote(version) {\n    log.Fatalf(\"version %q contains characters that require quoting; clean it\", version)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use clean semver tags or commit hashes as versions.","Avoid spaces, quotes, and @ inside version tokens.","Shell-quote arguments so stray spaces do not sneak in."],"tags":["go-toolchain","work","modules","validation","version"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}