{"record":{"id":"033e2d8da9f6321f","repo":"ipfs/kubo","slug":"parsing-current-version-q-w","errorCode":null,"errorMessage":"parsing current version %q: %w","messagePattern":"parsing current version %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/update.go","lineNumber":841,"sourceCode":"// trimVPrefix removes a leading \"v\" from a version string.\nfunc trimVPrefix(s string) string {\n\treturn strings.TrimPrefix(s, \"v\")\n}\n\n// normalizeVersion ensures a version string has a \"v\" prefix (for GitHub tags).\nfunc normalizeVersion(s string) string {\n\ts = strings.TrimSpace(s)\n\tif !strings.HasPrefix(s, \"v\") {\n\t\treturn \"v\" + s\n\t}\n\treturn s\n}\n\n// isNewerVersion returns true if target is newer than current.\nfunc isNewerVersion(current, target string) (bool, error) {\n\tcv, err := goversion.NewVersion(current)\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"parsing current version %q: %w\", current, err)\n\t}\n\ttv, err := goversion.NewVersion(target)\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"parsing target version %q: %w\", target, err)\n\t}\n\treturn tv.GreaterThan(cv), nil\n}\n","sourceCodeStart":823,"sourceCodeEnd":849,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/update.go#L823-L849","documentation":"isNewerVersion in core/commands/update.go compares two version strings using go-version. When the CURRENT version string (e.g. the running ipfs binary's version) cannot be parsed as a valid semver-ish version, the function wraps goversion.NewVersion's error with `parsing current version %q: %w`. It signals that the version-comparison input is malformed, not that the update check itself failed.","triggerScenarios":"Calling `ipfs update check` (or any command path that reaches isNewerVersion via the anonymous caller) when the current version string is empty, a dev build string like 'ipfs version 0.0.0-fsdf...', contains non-numeric junk ('unknown', 'canary+dirty'), or a malformed semver ('1.2' is fine but 'abc' is not).","commonSituations":"Running a locally built binary from a dirty git checkout whose version string was overridden, a truncated/corrupted version file in IPFS_PATH, tests passing placeholder strings, or a fork that injects a non-semver build metadata suffix.","solutions":["Print and fix the source of the current version: run `ipfs version --number` and correct whatever produces the malformed string (build ldflags, version file).","If testing, pass a valid semver string like '0.30.0' to isNewerVersion instead of a placeholder.","Strip extraneous build metadata/leading text before calling: trim to the core `X.Y.Z` segment or use goversion regex to validate.","Rebuild/install an official binary with `make build` or the official installer so CurrentVersion is a proper semver."],"exampleFix":"// before\nnewer, err := isNewerVersion(getVersion(), target) // getVersion() returns \"dev-dirty\"\n// after\ncur := getVersion()\nif _, perr := goversion.NewVersion(cur); perr != nil {\n\tcur = \"0.0.0\" // fall back to a parseable baseline for dev builds\n}\nnewer, err := isNewerVersion(cur, target)","handlingStrategy":"validation","validationCode":"if _, err := goversion.NewVersion(currentVersion); err != nil {\n\treturn fmt.Errorf(\"current version %q is not a valid version: %w\", currentVersion, err)\n}","typeGuard":"func isParseableVersion(v string) bool {\n\t_, err := goversion.NewVersion(v)\n\treturn err == nil\n}","tryCatchPattern":"newer, err := isNewerVersion(current, target)\nif err != nil {\n\tvar verr *goversion.Error\n\tif errors.As(err, &verr) { /* malformed input, not a network failure */ }\n\treturn fmt.Errorf(\"update check aborted: %w\", err)\n}","preventionTips":["Always build with the standard ldflags so the version string is a clean semver","Validate any version string with goversion.NewVersion before comparing","Trim 'v' prefixes and build metadata before parsing","Never pass user text or branch names directly as a version"],"tags":["version-parsing","semver","cli","self-update"],"backgroundTag":"invalid-version-string","analyzedSha":"329838acdfafae224582930457efe80aa217afc0","analyzedAt":"2026-09-03T18:30:52.135Z","contentChangedAt":"2026-09-03T18:30:52.135Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}