{"record":{"id":"eb1a312312cb7ae3","repo":"dgraph-io/dgraph","slug":"version-can-t-be-empty-and-must-start-with-v-e","errorCode":null,"errorMessage":"version can't be empty and must start with `v`. E.g.: v1.2.2","messagePattern":"version can't be empty and must start with `v`\\. E\\.g\\.: v1\\.2\\.2","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upgrade/upgrade.go","lineNumber":219,"sourceCode":"\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\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","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/upgrade/upgrade.go#L201-L237","documentation":"parseVersionFromString requires a non-empty version string that starts with a literal 'v'. This error is returned when the value is empty (e.g. missing flag value or empty env/config) or lacks the v prefix, so it cannot be a valid Dgraph version tag.","triggerScenarios":"Passing \"\" or a value like \"21.03.0\" (no v) to parseVersionFromString — e.g. dgraph upgrade with an empty --from/--to, or the config key holding an empty string.","commonSituations":"Unset environment variables interpolated into flags, YAML/config files with empty version keys, forgetting the leading v used in Dgraph release tags.","solutions":["Set the flag/config value to a full tag with the v prefix, e.g. v21.03.2.","Check the config source (env var, conf string) actually holds the version; unset/empty values cause this error.","Trim whitespace only — the prefix check happens after TrimSpace, so 'v21.03.2 ' is fine but ' 21.03.2' fails (no v).","Verify with dgraph version which tag format your binaries use and mirror it."],"exampleFix":"// before\nFROM_VER=$(sed 's/^dgraph\\///' image) # yields \"21.03.0\"\ndgraph upgrade offline -f \"$FROM_VER\" -t v21.03.2\n// after\nFROM_VER=\"v$(sed 's/^dgraph\\///' image)\"\ndgraph upgrade offline -f \"$FROM_VER\" -t v21.03.2","handlingStrategy":"validation","validationCode":"func isParsableVersion(v string) bool {\n\tv = strings.TrimSpace(v)\n\treturn v != \"\" && strings.HasPrefix(v, \"v\")\n}\n// use: if !isParsableVersion(flagValue) { log.Fatal(\"version must be non-empty and start with v\") }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default version flags to a known-good tag instead of empty env vars","Reject empty strings in config files feeding the command","Ensure exactly one leading v (not vv or none)","Automate version detection with `dgraph version` output"],"tags":["cli","versioning","validation"],"backgroundTag":"invalid-version-format","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}