{"record":{"id":"f5c57990a2dd0a6f","repo":"crowdsecurity/crowdsec","slug":"while-syncing-s-s-w","errorCode":null,"errorMessage":"while syncing %s %s: %w","messagePattern":"while syncing (.+?) (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/cwhub/sync.go","lineNumber":572,"sourceCode":"\n\t\th.logger.Debugf(\"installed (%s) - status: %d | installed: %s | latest: %s | full: %+v\", item.Name, vs, item.State.LocalVersion, item.Version, item.Versions)\n\t}\n\n\th.Warnings = removeDuplicates(warnings)\n\n\treturn nil\n}\n\nfunc (i *Item) detectVersionFromHash(hash string) (version string, found bool, err error) {\n\t// let's reverse sort the versions to deal with hash collisions (#154)\n\tversions := make([]string, 0, len(i.Versions))\n\tfor k := range i.Versions {\n\t\tversions = append(versions, k)\n\t}\n\n\tsorted, err := sortedVersions(versions)\n\tif err != nil {\n\t\treturn \"\", false, fmt.Errorf(\"while syncing %s %s: %w\", i.Type, i.FileName, err)\n\t}\n\n\tfor _, version := range sorted {\n\t\tif i.Versions[version].Digest == hash {\n\t\t\treturn version, true, nil\n\t\t}\n\t}\n\n\treturn \"?\", false, nil\n}\n\nfunc (i *Item) setVersionState(path string, inhub bool) error {\n\tvar err error\n\n\tif !inhub {\n\t\ti.State.LocalPath = path\n\t}\n","sourceCodeStart":554,"sourceCodeEnd":590,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/cwhub/sync.go#L554-L590","documentation":"Returned by detectVersionFromHash when sortedVersions fails to sort the hub item's known version strings into a semver-like order. It wraps the underlying sorting error with the item type and file name for context, and aborts matching a local file hash against a downloaded version.","triggerScenarios":"setVersionState -> detectVersionFromHash is called with a local hash while the item's i.Versions map contains version keys that the hashicorp/go-version parser cannot parse (e.g. malformed tags fetched from the hub).","commonSituations":"A hub index with irregular or non-semver release tags, a corrupted/partially written hub index on disk, or an item whose version metadata was fetched from a nonstandard remote.","solutions":["Inspect i.Versions keys for malformed version strings and re-download the hub index (cscli hub update / delete the stale hub index cache).","Upgrade crowdsec so the parser accepts the tag format used upstream.","Report the offending version string upstream if it comes from the official hub.","As a workaround, reinstall the item with cscli hub install/upgrade to rebuild its version metadata."],"exampleFix":"// before (debugging): log versions before sorting\nsorted, err := sortedVersions(versions)\n// after: log the offending input\nif err != nil {\n    return \"\", false, fmt.Errorf(\"while syncing %s %s (versions=%v): %w\", i.Type, i.FileName, versions, err)\n}","handlingStrategy":"try-catch","validationCode":"for v := range item.Versions {\n    if _, err := goversion.NewVersion(v); err != nil {\n        return fmt.Errorf(\"hub item has unparsable version %q\", v)\n    }\n}","typeGuard":null,"tryCatchPattern":"ver, ok, err := item.DetectVersionFromHash(hash)\nif err != nil {\n    var pathErr *fs.PathError\n    if errors.As(err, &pathErr) { /* hub index corrupt */ }\n    return fmt.Errorf(\"version detection failed for %s: %w\", item.FileName, err)\n}","preventionTips":["Keep the hub index fresh with cscli hub update","Report malformed release tags upstream instead of editing cached metadata","Don't hand-edit files under /var/lib/crowdsec/data"],"tags":["go","hub","versioning"],"backgroundTag":"invalid-identifier-format","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}