crowdsecurity/crowdsec · error
while syncing %s %s: %w
Error message
while syncing %s %s: %w
What it means
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.
Source
Thrown at pkg/cwhub/sync.go:572
h.logger.Debugf("installed (%s) - status: %d | installed: %s | latest: %s | full: %+v", item.Name, vs, item.State.LocalVersion, item.Version, item.Versions)
}
h.Warnings = removeDuplicates(warnings)
return nil
}
func (i *Item) detectVersionFromHash(hash string) (version string, found bool, err error) {
// let's reverse sort the versions to deal with hash collisions (#154)
versions := make([]string, 0, len(i.Versions))
for k := range i.Versions {
versions = append(versions, k)
}
sorted, err := sortedVersions(versions)
if err != nil {
return "", false, fmt.Errorf("while syncing %s %s: %w", i.Type, i.FileName, err)
}
for _, version := range sorted {
if i.Versions[version].Digest == hash {
return version, true, nil
}
}
return "?", false, nil
}
func (i *Item) setVersionState(path string, inhub bool) error {
var err error
if !inhub {
i.State.LocalPath = path
}
View on GitHub (pinned to 909b515798)
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.
Example fix
// before (debugging): log versions before sorting
sorted, err := sortedVersions(versions)
// after: log the offending input
if err != nil {
return "", false, fmt.Errorf("while syncing %s %s (versions=%v): %w", i.Type, i.FileName, versions, err)
} Defensive patterns
Strategy: try-catch
Validate before calling
for v := range item.Versions {
if _, err := goversion.NewVersion(v); err != nil {
return fmt.Errorf("hub item has unparsable version %q", v)
}
} Try / catch
ver, ok, err := item.DetectVersionFromHash(hash)
if err != nil {
var pathErr *fs.PathError
if errors.As(err, &pathErr) { /* hub index corrupt */ }
return fmt.Errorf("version detection failed for %s: %w", item.FileName, err)
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.
Related errors
- no hub configuration provided
- ErrUserCanceled
- no appsec rules in hub index
- no parsers in hub index
- no scenarios in hub index
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/f5c57990a2dd0a6f.
Report an issue: GitHub.