crowdsecurity/crowdsec · error
unable to parse duration
Error message
unable to parse duration
What it means
ParseDurationFail is a sentinel error meaning a duration string failed to parse, specifically via crowdsec's cstime.ParseDurationWithDays, which supports Go durations plus day-suffixed values (e.g. "4h", "3d"). It is returned from createDecisionBatch when a decision's duration field is malformed.
Source
Thrown at pkg/database/errors.go:15
package database
import "errors"
var (
UserExists = errors.New("user already exist")
UserNotExists = errors.New("user doesn't exist")
HashError = errors.New("unable to hash")
InsertFail = errors.New("unable to insert row")
QueryFail = errors.New("unable to query")
UpdateFail = errors.New("unable to update")
DeleteFail = errors.New("unable to delete")
ItemNotFound = errors.New("object not found")
ParseTimeFail = errors.New("unable to parse time")
ParseDurationFail = errors.New("unable to parse duration")
MarshalFail = errors.New("unable to serialize")
BulkError = errors.New("unable to insert bulk")
ParseType = errors.New("unable to parse type")
InvalidIPOrRange = errors.New("invalid ip address / range")
InvalidFilter = errors.New("invalid filter")
)
View on GitHub (pinned to 909b515798)
Solutions
- Use supported formats: Go duration strings ("300ms", "4h") or "<N>d" for days; convert weeks to hours/days first.
- If the decision should be permanent, omit Duration and use an empty/unexpired form per models spec instead of an unparseable value.
- Validate the duration in the producer before submitting: attempt cstime.ParseDurationWithDays yourself.
- Check the wrapped inner error for the exact offending value (echoed in the message).
Example fix
// before
decision.Duration = ptr("2w")
// after
decision.Duration = ptr("14d") // or "336h" Defensive patterns
Strategy: validation
Validate before calling
func validDuration(s string) bool {
_, err := cstime.ParseDurationWithDays(s)
return err == nil
}
// call before submitting: validDuration(*decision.Duration) Try / catch
if _, err := client.CreateAlert(ctx, alert); err != nil {
if errors.Is(err, database.ParseDurationFail) {
return fmt.Errorf("bad decision duration %q: use Go durations or Nd", err)
}
return err
} Prevention
- Use only Go duration strings or "<N>d" day format
- Convert weeks/months to hours/days before submitting
- Validate durations in producers with cstime.ParseDurationWithDays
When it happens
Trigger: createDecisionBatch processing decisions whose Duration string is not a valid Go duration or "Nd" day format, e.g. "2w" or an empty/blank string.
Common situations: Custom parsers pushing decisions with non-supported units (weeks, months), empty duration fields in alert JSON produced by third-party tooling, locale-specific spellings.
Understand the failure class
Background: "invalid duration" / "failed to parse duration": why your timeout, interval, or TTL string is rejected and which formats each library accepts — this error's family across 32 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- unable to parse time
- unable to parse type
- no database configuration provided
- unable to update
- unable to delete
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/819bd1c1457e796c.
Report an issue: GitHub.