{"record":{"id":"71265cc76d9aa170","repo":"crowdsecurity/crowdsec","slug":"s-ttl-must-be-set","errorCode":null,"errorMessage":"%s: ttl must be set","messagePattern":"(.+?): ttl must be set","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/parser/stash.go","lineNumber":47,"sourceCode":"\tValueExpression *vm.Program\n\tTTLVal          time.Duration\n}\n\nfunc (s *Stash) Validate() error {\n\tif s.Name == \"\" {\n\t\treturn errors.New(\"name must be set\")\n\t}\n\n\tif s.Value == \"\" {\n\t\treturn fmt.Errorf(\"%s: value expression must be set\", s.Name)\n\t}\n\n\tif s.Key == \"\" {\n\t\treturn fmt.Errorf(\"%s: key expression must be set\", s.Name)\n\t}\n\n\tif s.TTL == \"\" {\n\t\treturn fmt.Errorf(\"%s: ttl must be set\", s.Name)\n\t}\n\n\tif s.Strategy == \"\" {\n\t\ts.Strategy = \"LRU\"\n\t}\n\n\t// should be configurable\n\tif s.MaxMapSize == 0 {\n\t\ts.MaxMapSize = 100\n\t}\n\n\treturn nil\n}\n\nfunc (s *Stash) Compile(logger *log.Entry) (*RuntimeStash, error) {\n\tvar err error\n\n\trs := &RuntimeStash{Config: s}","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/parser/stash.go#L29-L65","documentation":"Stash.Validate() requires a `ttl` string, later parsed as a Go duration, to bound cache entries. Without it the stash would keep entries forever, so validation fails; if ttl is present, Strategy defaults to LRU automatically.","triggerScenarios":"A `stash:` stanza lacks the `ttl:` field (or it is empty); Validate() runs at config load time.","commonSituations":"Minimal stash examples that omit ttl; a commented-out ttl line left in the config file.","solutions":["Add a `ttl:` duration to the stash, e.g. `ttl: 1h` or `ttl: 30m`.","Verify indentation so ttl belongs to the same stash mapping.","Restart crowdsec to confirm the stash validates and defaults Strategy to LRU."],"exampleFix":"// before\n- name: my-stash\n  key: evt.Parsed.src_ip\n  value: evt.Parsed.src_ip\n// after\n- name: my-stash\n  key: evt.Parsed.src_ip\n  value: evt.Parsed.src_ip\n  ttl: 1h","handlingStrategy":"validation","validationCode":"if s.TTL == \"\" { return fmt.Errorf(\"stash %q: ttl required (e.g. 1h)\", s.Name) }","typeGuard":null,"tryCatchPattern":"if err := stash.Validate(); err != nil {\n    return fmt.Errorf(\"invalid stash config: %w\", err)\n}","preventionTips":["Include ttl in every stash template/snippet you reuse.","Remember strategy defaults to LRU; only ttl, key, value are mandatory."],"tags":["parser","stash","validation","config"],"backgroundTag":"missing-required-config-field","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}