{"record":{"id":"6972bd41aceb8827","repo":"dgraph-io/dgraph","slug":"error-parsing-flag-s-w","errorCode":null,"errorMessage":"error parsing flag `%s`: %w","messagePattern":"error parsing flag `(.+?)`: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upgrade/upgrade.go","lineNumber":203,"sourceCode":"\tfromVersionParsed, err := parseVersionFromString(Upgrade.Conf.GetString(from))\n\tif err != nil {\n\t\treturn nil, formatAsFlagParsingError(from, err)\n\t}\n\n\ttoVersionParsed, err := parseVersionFromString(Upgrade.Conf.GetString(to))\n\tif err != nil {\n\t\treturn nil, formatAsFlagParsingError(to, err)\n\t}\n\n\tif fromVersionParsed.Compare(toVersionParsed) != less {\n\t\treturn nil, fmt.Errorf(\"error: `%s` must be less than `%s`\", from, to)\n\t}\n\n\treturn &commandInput{fromVersion: fromVersionParsed, toVersion: toVersionParsed}, nil\n}\n\nfunc formatAsFlagParsingError(flag string, err error) error {\n\treturn fmt.Errorf(\"error parsing flag `%s`: %w\", flag, err)\n}\n\n// parseVersionFromString parses a version given as string to internal representation.\n// Some examples for input and output:\n//  1. input : v1.2.2\n//     output: &version{major: 1, minor: 2, patch: 2}, nil\n//  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","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/upgrade/upgrade.go#L185-L221","documentation":"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.","triggerScenarios":"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).","commonSituations":"Omitting the leading v, using image tags like latest or main as versions, shell scripts interpolating untrimmed/unset variables.","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."],"exampleFix":"// before\ndgraph upgrade offline -f 21.03.0 -t v21.03.2\n// after\ndgraph upgrade offline -f v21.03.0 -t v21.03.2","handlingStrategy":"validation","validationCode":"var semverRe = regexp.MustCompile(`^v\\d+\\.\\d+\\.\\d+$`)\nfunc isValidVersionFlag(s string) bool { return semverRe.MatchString(strings.TrimSpace(s)) }\n// use: if !isValidVersionFlag(fromVer) || !isValidVersionFlag(toVer) { correct values first }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["cli","versioning","flag-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"}