{"record":{"id":"0dbb335e7e84a074","repo":"dgraph-io/dgraph","slug":"error-parsing-major-version-w","errorCode":null,"errorMessage":"error parsing major version: %w","messagePattern":"error parsing major version: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upgrade/upgrade.go","lineNumber":228,"sourceCode":"//  2. input : v20.03.0-beta.20200320\n//     output: &version{major: 20, minor: 3, patch: 0}, nil\n//  3. input : 1.2.2\n//     output: nil, error\n//  4. input : v1.2.2s\n//     output: nil, error\nfunc parseVersionFromString(v string) (*version, error) {\n\tv = strings.TrimSpace(v)\n\tif v == \"\" || v[:1] != \"v\" {\n\t\treturn nil, fmt.Errorf(\"version can't be empty and must start with `v`. E.g.: v1.2.2\")\n\t}\n\n\tversionSplit := strings.Split(v[1:], \".\")\n\tresult := &version{}\n\tvar err error\n\n\tresult.major, err = strconv.Atoi(versionSplit[0])\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error parsing major version: %w\", err)\n\t}\n\n\tresult.minor, err = strconv.Atoi(versionSplit[1])\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error parsing minor version: %w\", err)\n\t}\n\n\t// the third part of split might contain some extra things like `beta` appended with -,\n\t// so split again and take the first part as patch\n\tpatchSplit := strings.Split(versionSplit[2], \"-\")\n\tresult.patch, err = strconv.Atoi(patchSplit[0])\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error parsing patch version: %w\", err)\n\t}\n\n\treturn result, nil\n}\n","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/upgrade/upgrade.go#L210-L246","documentation":"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).","triggerScenarios":"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'.","commonSituations":"Duplicated v prefix (vv21.03.0), branch names or image tags used as versions, copy-paste errors adding characters into the version string.","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."],"exampleFix":"// before\ndgraph upgrade offline -f vv21.03.0 -t v21.03.2\n// after\ndgraph upgrade offline -f v21.03.0 -t v21.03.2","handlingStrategy":"validation","validationCode":"var fullSemverRe = regexp.MustCompile(`^v\\d+\\.\\d+\\.\\d+$`)\nfunc isStrictSemver(v string) bool { return fullSemverRe.MatchString(strings.TrimSpace(v)) }\n// use: if !isStrictSemver(fromVer) { log.Fatal(\"expected vMAJOR.MINOR.PATCH, got \" + fromVer) }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["cli","versioning","parsing"],"backgroundTag":"invalid-version-format","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}