{"record":{"id":"7b09373af81dafd5","repo":"GoogleContainerTools/skaffold","slug":"parsing-semver-w","errorCode":null,"errorMessage":"parsing semver: %w","messagePattern":"parsing semver: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/skaffold/version/version.go","lineNumber":94,"sourceCode":"// UserAgentWithClient returns a conformant value for HTTP `User-Agent` headers that includes\n// the client value provided with the `--user` flag.  If there is no client value, then the value will be equivalent\n// to `UserAgent()`.  Otherwise it is of the form `skaffold/<version> (<os>/<arch>) <client>`, and the version\n// will be omitted if not available.\n// Use UserAgentWithClient method to record requests from skaffold CLI users vs\n// other clients.\nfunc UserAgentWithClient() string {\n\tif client == \"\" {\n\t\treturn UserAgent()\n\t}\n\treturn fmt.Sprintf(\"%s %s\", UserAgent(), client)\n}\n\nfunc ParseVersion(version string) (semver.Version, error) {\n\t// Strip the leading 'v' in our version strings\n\tversion = strings.TrimSpace(version)\n\tv, err := semver.Parse(strings.TrimLeft(version, \"v\"))\n\tif err != nil {\n\t\treturn semver.Version{}, fmt.Errorf(\"parsing semver: %w\", err)\n\t}\n\treturn v, nil\n}\n","sourceCodeStart":76,"sourceCodeEnd":98,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/version/version.go#L76-L98","documentation":"ParseVersion converts Skaffold version strings into a semver.Version, stripping a leading 'v'. If the remaining string is not valid semantic version syntax, the underlying semver.Parse error is wrapped as 'parsing semver'. It is used when checking pre-release versions and the latest available release.","triggerScenarios":"ParseVersion receives a string like '', 'not-a-version', '1.39', 'v1.2.3.4', or output of `skaffold version` / a GitHub release tag that isn't strictly semver (missing patch, extra characters, whitespace-embedded junk).","commonSituations":"Custom/local builds of Skaffold reporting non-semver version strings (e.g. 'v0.0.0-unknown' variants or git descriptions); proxy/mirror returning an HTML error page where a version JSON was expected; parsing third-party tool versions with looser schemes.","solutions":["Check the input string with `skaffold version` or the release tag; ensure it is valid semver (MAJOR.MINOR.PATCH)","Install an official Skaffold release whose `skaffold version` prints proper semver","Trim stray characters/newlines from version strings before parsing","If parsing third-party versions, normalize them (pad missing components) before calling ParseVersion"],"exampleFix":"// before\nParseVersion(\"1.39\")              // parsing semver: ...\n// after\nParseVersion(\"v1.39.2\")           // OK -> 1.39.2","handlingStrategy":"validation","validationCode":"func parseSafe(version string) (semver.Version, error) {\n    v := strings.TrimSpace(strings.TrimPrefix(strings.TrimSpace(version), \"v\"))\n    parts := strings.Split(v, \".\")\n    if len(parts) < 3 {\n        return semver.Version{}, fmt.Errorf(\"not full semver: %q\", version)\n    }\n    return version.ParseVersion(version)\n}","typeGuard":"func looksLikeSemver(s string) bool {\n    t := strings.TrimPrefix(strings.TrimSpace(s), \"v\")\n    parts := strings.Split(t, \".\")\n    return len(parts) >= 3 && !strings.ContainsAny(t, \" \\t\\n\")\n}","tryCatchPattern":"v, err := version.ParseVersion(input)\nif err != nil {\n    // log raw input for inspection; treat as unknown version, skip comparison\n}","preventionTips":["Validate version strings match ^v?\\d+\\.\\d+\\.\\d+ before parsing","Install official Skaffold builds so `skaffold version` prints clean semver","Trim HTTP/response bodies when extracting versions from APIs to avoid HTML leakage","Pad partial versions to MAJOR.MINOR.PATCH before parsing"],"tags":["semver","versioning","parsing"],"backgroundTag":"invalid-semver-string","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}