golang/go · error
invalid version interval: %q
Error message
invalid version interval: %q
What it means
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).
Source
Thrown at src/cmd/go/internal/modcmd/edit.go:402
if path != arg && !allowedVersionArg(version) {
return path, version, fmt.Errorf("invalid %s version: %q", adj, version)
}
return path, version, nil
}
// parseVersionInterval parses a single version like "v1.2.3" or a closed
// interval like "[v1.2.3,v1.4.5]". Note that a single version has the same
// representation as an interval with equal upper and lower bounds: both
// Low and High are set.
func parseVersionInterval(arg string) (modfile.VersionInterval, error) {
if !strings.HasPrefix(arg, "[") {
if !allowedVersionArg(arg) {
return modfile.VersionInterval{}, fmt.Errorf("invalid version: %q", arg)
}
return modfile.VersionInterval{Low: arg, High: arg}, nil
}
if !strings.HasSuffix(arg, "]") {
return modfile.VersionInterval{}, fmt.Errorf("invalid version interval: %q", arg)
}
s := arg[1 : len(arg)-1]
before, after, found := strings.Cut(s, ",")
if !found {
return modfile.VersionInterval{}, fmt.Errorf("invalid version interval: %q", arg)
}
low := strings.TrimSpace(before)
high := strings.TrimSpace(after)
if !allowedVersionArg(low) || !allowedVersionArg(high) {
return modfile.VersionInterval{}, fmt.Errorf("invalid version interval: %q", arg)
}
return modfile.VersionInterval{Low: low, High: high}, nil
}
// allowedVersionArg returns whether a token may be used as a version in go.mod.
// We don't call modfile.CheckPathVersion, because that insists on versions
// being in semver form, but here we want to allow versions like "master" or
// "1234abcdef", which the go command will resolve the next time it runs (orView on GitHub (pinned to b6b368adc5)
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
Example fix
// before go mod edit -exclude=[v1.2.3,v1.4.5 // after go mod edit -exclude=[v1.2.3,v1.4.5]
Defensive patterns
Strategy: validation
Validate before calling
// Validate interval format before passing to go mod edit
func validateVersionInterval(arg string) error {
if strings.HasPrefix(arg, "[") && !strings.HasSuffix(arg, "]") {
return fmt.Errorf("interval must end with ]: %q", arg)
}
return nil
} Type guard
func isClosedInterval(s string) bool {
return strings.HasPrefix(s, "[") && strings.HasSuffix(s, "]")
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- expecting a Go version like %q
- non-semver module version %q
- invalid version %q
- maximum supported Go version is %s
- non-canonical module version %q
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/1693bb44241f7303.
Report an issue: GitHub.