{"record":{"id":"1693bb44241f7303","repo":"golang/go","slug":"invalid-version-interval-q","errorCode":null,"errorMessage":"invalid version interval: %q","messagePattern":"invalid version interval: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modcmd/edit.go","lineNumber":402,"sourceCode":"\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// parseVersionInterval parses a single version like \"v1.2.3\" or a closed\n// interval like \"[v1.2.3,v1.4.5]\". Note that a single version has the same\n// representation as an interval with equal upper and lower bounds: both\n// Low and High are set.\nfunc parseVersionInterval(arg string) (modfile.VersionInterval, error) {\n\tif !strings.HasPrefix(arg, \"[\") {\n\t\tif !allowedVersionArg(arg) {\n\t\t\treturn modfile.VersionInterval{}, fmt.Errorf(\"invalid version: %q\", arg)\n\t\t}\n\t\treturn modfile.VersionInterval{Low: arg, High: arg}, nil\n\t}\n\tif !strings.HasSuffix(arg, \"]\") {\n\t\treturn modfile.VersionInterval{}, fmt.Errorf(\"invalid version interval: %q\", arg)\n\t}\n\ts := arg[1 : len(arg)-1]\n\tbefore, after, found := strings.Cut(s, \",\")\n\tif !found {\n\t\treturn modfile.VersionInterval{}, fmt.Errorf(\"invalid version interval: %q\", arg)\n\t}\n\tlow := strings.TrimSpace(before)\n\thigh := strings.TrimSpace(after)\n\tif !allowedVersionArg(low) || !allowedVersionArg(high) {\n\t\treturn modfile.VersionInterval{}, fmt.Errorf(\"invalid version interval: %q\", arg)\n\t}\n\treturn modfile.VersionInterval{Low: low, High: high}, nil\n}\n\n// allowedVersionArg returns whether a token may be used as a version in go.mod.\n// We don't call modfile.CheckPathVersion, because that insists on versions\n// being in semver form, but here we want to allow versions like \"master\" or\n// \"1234abcdef\", which the go command will resolve the next time it runs (or","sourceCodeStart":384,"sourceCodeEnd":420,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modcmd/edit.go#L384-L420","documentation":"Thrown by parseVersionInterval when an argument begins with '[' but does not end with ']'. The function expects a closed interval notation like '[v1.2.3,v1.4.5]'; a missing closing bracket makes the interval malformed and unparseable. This is used by `go mod edit` commands that accept version interval arguments (e.g., `-require`, `-exclude`, `-replace` with intervals).","triggerScenarios":"Calling `go mod edit` with a version interval argument that starts with '[' but lacks the closing ']', such as `-exclude=[v1.2.3,v1.4.5` or `-replace=old@v1.0.0=[v1.1.0`. Any argument matching `strings.HasPrefix(arg, \"[\")` but NOT `strings.HasSuffix(arg, \"]\")` hits this branch.","commonSituations":"Typo in shell quoting that strips the trailing bracket; copy-paste from documentation that truncated the example; shell glob or variable expansion that mangled the closing ']'; using a bracket notation when a single version was intended.","solutions":["Add the missing closing ']' to complete the interval: `[v1.2.3,v1.4.5` → `[v1.2.3,v1.4.5]`","If a single version is intended, drop the brackets entirely: `[v1.2.3]` → `v1.2.3`","Check shell quoting: ensure the brackets are inside single or double quotes to prevent shell interpretation"],"exampleFix":"// before\ngo mod edit -exclude=[v1.2.3,v1.4.5\n// after\ngo mod edit -exclude=[v1.2.3,v1.4.5]","handlingStrategy":"validation","validationCode":"// Validate interval format before passing to go mod edit\nfunc validateVersionInterval(arg string) error {\n    if strings.HasPrefix(arg, \"[\") && !strings.HasSuffix(arg, \"]\") {\n        return fmt.Errorf(\"interval must end with ]: %q\", arg)\n    }\n    return nil\n}","typeGuard":"func isClosedInterval(s string) bool {\n    return strings.HasPrefix(s, \"[\") && strings.HasSuffix(s, \"]\")\n}","tryCatchPattern":null,"preventionTips":["Always quote interval arguments in single quotes to prevent shell interpretation","Use bare versions (no brackets) when a single version suffices","Validate interval syntax in scripts before invoking go mod edit"],"tags":["go","go-mod","version","validation","cli-argument"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}