{"record":{"id":"819bd1c1457e796c","repo":"crowdsecurity/crowdsec","slug":"unable-to-parse-duration","errorCode":null,"errorMessage":"unable to parse duration","messagePattern":"unable to parse duration","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/database/errors.go","lineNumber":15,"sourceCode":"package database\n\nimport \"errors\"\n\nvar (\n\tUserExists        = errors.New(\"user already exist\")\n\tUserNotExists     = errors.New(\"user doesn't exist\")\n\tHashError         = errors.New(\"unable to hash\")\n\tInsertFail        = errors.New(\"unable to insert row\")\n\tQueryFail         = errors.New(\"unable to query\")\n\tUpdateFail        = errors.New(\"unable to update\")\n\tDeleteFail        = errors.New(\"unable to delete\")\n\tItemNotFound      = errors.New(\"object not found\")\n\tParseTimeFail     = errors.New(\"unable to parse time\")\n\tParseDurationFail = errors.New(\"unable to parse duration\")\n\tMarshalFail       = errors.New(\"unable to serialize\")\n\tBulkError         = errors.New(\"unable to insert bulk\")\n\tParseType         = errors.New(\"unable to parse type\")\n\tInvalidIPOrRange  = errors.New(\"invalid ip address / range\")\n\tInvalidFilter     = errors.New(\"invalid filter\")\n)\n","sourceCodeStart":1,"sourceCodeEnd":22,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/database/errors.go#L1-L22","documentation":"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.","triggerScenarios":"createDecisionBatch processing decisions whose Duration string is not a valid Go duration or \"Nd\" day format, e.g. \"2w\" or an empty/blank string.","commonSituations":"Custom parsers pushing decisions with non-supported units (weeks, months), empty duration fields in alert JSON produced by third-party tooling, locale-specific spellings.","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)."],"exampleFix":"// before\ndecision.Duration = ptr(\"2w\")\n// after\ndecision.Duration = ptr(\"14d\") // or \"336h\"","handlingStrategy":"validation","validationCode":"func validDuration(s string) bool {\n    _, err := cstime.ParseDurationWithDays(s)\n    return err == nil\n}\n// call before submitting: validDuration(*decision.Duration)","typeGuard":null,"tryCatchPattern":"if _, err := client.CreateAlert(ctx, alert); err != nil {\n    if errors.Is(err, database.ParseDurationFail) {\n        return fmt.Errorf(\"bad decision duration %q: use Go durations or Nd\", err)\n    }\n    return err\n}","preventionTips":["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"],"tags":["database","crowdsec","duration","parsing"],"backgroundTag":"invalid-duration-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"}