{"record":{"id":"92b547d1b63a98ff","repo":"crowdsecurity/crowdsec","slug":"s-key-expression-must-be-set","errorCode":null,"errorMessage":"%s: key expression must be set","messagePattern":"(.+?): key expression must be set","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/parser/stash.go","lineNumber":43,"sourceCode":"\ntype RuntimeStash struct {\n\tConfig          *Stash\n\tKeyExpression   *vm.Program\n\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","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/parser/stash.go#L25-L61","documentation":"Stash.Validate() requires a `key` expression, which computes the cache key under which the value is stored. An empty key means entries could not be looked up, so the stash config is rejected, with the stash name in the message.","triggerScenarios":"A `stash:` stanza sets name/value/ttl but leaves `key:` empty or absent; Validate() is invoked during configuration load/validation.","commonSituations":"Copy-pasting a stash example and deleting the key line; YAML key named `keys` (plural) by mistake so `key` stays empty.","solutions":["Add a `key:` expr expression to the stash, e.g. `key: evt.Parsed.src_ip`.","Ensure the YAML field is spelled `key` and indented under the correct stash entry.","Reload the configuration to confirm validation passes."],"exampleFix":"// before\n- name: my-stash\n  value: evt.Parsed.src_ip\n  ttl: 1h\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.Key == \"\" { return fmt.Errorf(\"stash %q: key expression required\", s.Name) }","typeGuard":null,"tryCatchPattern":"if err := stash.Validate(); err != nil {\n    return fmt.Errorf(\"invalid stash config: %w\", err)\n}","preventionTips":["Copy stash stanzas from official hub examples so key/value/ttl are all present.","Watch for singular `key:` vs plural field-name typos in YAML."],"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-14T00:17:10.932Z"}