dgraph-io/dgraph · error
error parsing flag `%s`: %w
Error message
error parsing flag `%s`: %w
What it means
formatAsFlagParsingError wraps a parseVersionFromString failure with the flag name that had the bad value. It is produced when the --from or --to value passed to dgraph upgrade cannot be parsed as a vMAJOR.MINOR.PATCH version string.
Source
Thrown at upgrade/upgrade.go:203
fromVersionParsed, err := parseVersionFromString(Upgrade.Conf.GetString(from))
if err != nil {
return nil, formatAsFlagParsingError(from, err)
}
toVersionParsed, err := parseVersionFromString(Upgrade.Conf.GetString(to))
if err != nil {
return nil, formatAsFlagParsingError(to, err)
}
if fromVersionParsed.Compare(toVersionParsed) != less {
return nil, fmt.Errorf("error: `%s` must be less than `%s`", from, to)
}
return &commandInput{fromVersion: fromVersionParsed, toVersion: toVersionParsed}, nil
}
func formatAsFlagParsingError(flag string, err error) error {
return fmt.Errorf("error parsing flag `%s`: %w", flag, err)
}
// parseVersionFromString parses a version given as string to internal representation.
// Some examples for input and output:
// 1. input : v1.2.2
// output: &version{major: 1, minor: 2, patch: 2}, nil
// 2. input : v20.03.0-beta.20200320
// output: &version{major: 20, minor: 3, patch: 0}, nil
// 3. input : 1.2.2
// output: nil, error
// 4. input : v1.2.2s
// output: nil, error
func parseVersionFromString(v string) (*version, error) {
v = strings.TrimSpace(v)
if v == "" || v[:1] != "v" {
return nil, fmt.Errorf("version can't be empty and must start with `v`. E.g.: v1.2.2")
}
View on GitHub (pinned to 759e242be6)
Solutions
- Pass an exact semver string with a leading v, e.g. -f v21.03.2 -t v21.03.3.
- Check the wrapped error after 'error parsing flag' to see the specific parse failure and correct that component.
- Trim whitespace/quotes in scripts before passing the version.
- Run dgraph version to confirm your current version string format.
Example fix
// before dgraph upgrade offline -f 21.03.0 -t v21.03.2 // after dgraph upgrade offline -f v21.03.0 -t v21.03.2
Defensive patterns
Strategy: validation
Validate before calling
var semverRe = regexp.MustCompile(`^v\d+\.\d+\.\d+$`)
func isValidVersionFlag(s string) bool { return semverRe.MatchString(strings.TrimSpace(s)) }
// use: if !isValidVersionFlag(fromVer) || !isValidVersionFlag(toVer) { correct values first } Prevention
- Always include the leading v in version flags
- Use exact release tags, not image names like latest
- Trim shell variables before passing them
- Check the inner error after 'error parsing flag' to identify the malformed component
When it happens
Trigger: Running dgraph upgrade with a malformed --from or --to value such as 21.03 (no v prefix), v21.03 (missing patch), or v21.03.0.0 (extra component).
Common situations: Omitting the leading v, using image tags like latest or main as versions, shell scripts interpolating untrimmed/unset variables.
Related errors
- error: `%s` must be less than `%s`
- version can't be empty and must start with `v`. E.g.: v1.2.2
- error parsing major version: %w
- Key size value is too large (x > 4096)
- Key size value must be a factor of 2
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/6972bd41aceb8827.
Report an issue: GitHub.