{"record":{"id":"386fd1243ad1b1d2","repo":"ipfs/kubo","slug":"parsing-target-version-q-w","errorCode":null,"errorMessage":"parsing target version %q: %w","messagePattern":"parsing target version %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/update.go","lineNumber":845,"sourceCode":"\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":827,"sourceCodeEnd":849,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/update.go#L827-L849","documentation":"The mirror case of error 445 in isNewerVersion: the TARGET version string passed to goversion.NewVersion is not a parseable version, so the comparison aborts with `parsing target version %q: %w`. The library wraps the underlying go-version parse error to show exactly which string failed.","triggerScenarios":"`ipfs update apply <version>` / `update check` invoked with a target that is empty, a tag like 'v' or 'latest-unparsed', contains spaces or invalid characters, or an API response produced a version field that is not semver-shaped.","commonSituations":"Typing a human label ('latest', 'stable') directly as the target version, copy-pasting a git tag with a 'v' prefix plus extra text, a mocked/test harness feeding bad strings, or a upstream release name that is not a plain semver.","solutions":["Check the exact argument: run `ipfs update check` first and use a version exactly as listed (e.g. `v0.30.0`).","Strip invalid characters / 'v' prefix / whitespace and trailing notes before retrying: target = strings.TrimPrefix(target, \"v\").","If the target came from an API response, validate it with goversion.NewVersion before passing it on and surface a clearer message.","Upgrade the kubo version so update.go fixes any stricter/looser parsing, or patch isNewerVersion to normalize the input."],"exampleFix":"// before\nnewer, err := isNewerVersion(current, \"latest\") // unparseable\n// after\ntarget := strings.TrimPrefix(strings.TrimSpace(userInput), \"v\")\nif _, perr := goversion.NewVersion(target); perr != nil {\n\treturn fmt.Errorf(\"invalid target version %q\", userInput)\n}\nnewer, err := isNewerVersion(current, target)","handlingStrategy":"validation","validationCode":"target = strings.TrimPrefix(strings.TrimSpace(target), \"v\")\nif _, err := goversion.NewVersion(target); err != nil {\n\treturn fmt.Errorf(\"invalid target version %q\", target)\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\tif strings.Contains(err.Error(), \"parsing target version\") {\n\t\treturn fmt.Errorf(\"%q is not a valid version; use one from `ipfs update check`\", target)\n\t}\n\treturn err\n}","preventionTips":["Use `ipfs update check` output verbatim as the target version","Normalize input: TrimSpace, TrimPrefix \"v\"","Reject symbolic names like 'latest' before calling the updater","Sanitize pasted text (strip whitespace, notes, URLs) before parsing"],"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"}