dgraph-io/dgraph · error
error parsing major version: %w
Error message
error parsing major version: %w
What it means
parseVersionFromString splits the version on '.' and uses strconv.Atoi on each component. This error wraps an Atoi failure on the major component, meaning the text before the first dot is not a plain integer (after the mandatory v prefix).
Source
Thrown at upgrade/upgrade.go:228
// 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")
}
versionSplit := strings.Split(v[1:], ".")
result := &version{}
var err error
result.major, err = strconv.Atoi(versionSplit[0])
if err != nil {
return nil, fmt.Errorf("error parsing major version: %w", err)
}
result.minor, err = strconv.Atoi(versionSplit[1])
if err != nil {
return nil, fmt.Errorf("error parsing minor version: %w", err)
}
// the third part of split might contain some extra things like `beta` appended with -,
// so split again and take the first part as patch
patchSplit := strings.Split(versionSplit[2], "-")
result.patch, err = strconv.Atoi(patchSplit[0])
if err != nil {
return nil, fmt.Errorf("error parsing patch version: %w", err)
}
return result, nil
}
View on GitHub (pinned to 759e242be6)
Solutions
- Correct the major segment to a plain integer: v21.03.2, not vv21.03.2 or vlatest.
- Remove any extra prefix characters after v before the first number.
- Validate the version with a regex like ^v\d+\.\d+\.\d+$ before invoking the command.
- Check the wrapped %w error to confirm it is a strconv syntax error and see the offending text.
Example fix
// before dgraph upgrade offline -f vv21.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 fullSemverRe = regexp.MustCompile(`^v\d+\.\d+\.\d+$`)
func isStrictSemver(v string) bool { return fullSemverRe.MatchString(strings.TrimSpace(v)) }
// use: if !isStrictSemver(fromVer) { log.Fatal("expected vMAJOR.MINOR.PATCH, got " + fromVer) } Prevention
- Match Dgraph release tag format exactly: vMAJOR.MINOR.PATCH
- Avoid duplicating the v prefix (vv21.03.0)
- Never pass branch names or image tags as versions
- Validate with a regex before invoking dgraph upgrade
When it happens
Trigger: Passing a version whose major segment is non-numeric, e.g. vlatest.0, vv21.03.0, or vx.2.2 — Atoi fails and the error is wrapped with 'error parsing major version'.
Common situations: Duplicated v prefix (vv21.03.0), branch names or image tags used as versions, copy-paste errors adding characters into the version string.
Related errors
- error: `%s` must be less than `%s`
- error parsing flag `%s`: %w
- version can't be empty and must start with `v`. E.g.: v1.2.2
- NQuad failed sanity check. Subject: %q, Predicate: %q, Objec
- expected '(', found: %s
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/0dbb335e7e84a074.
Report an issue: GitHub.