{"record":{"id":"fc1bd0604011c9f9","repo":"gastownhall/beads","slug":"could-not-generate-key-from-content-use-key-to","errorCode":null,"errorMessage":"could not generate key from content; use --key to specify one","messagePattern":"could not generate key from content; use --key to specify one","errorType":"validation","errorClass":"memoryops.ErrValidation","httpStatus":null,"severity":"warning","filePath":"internal/memoryapi/memoryapi.go","lineNumber":129,"sourceCode":"\tif err := ValidateContent(content); err != nil {\n\t\treturn \"\", err\n\t}\n\tif key != \"\" {\n\t\t// THE SAME RULE READS AND WRITES USE. ValidateKey — which Recall and\n\t\t// Forget run — refuses a key that is empty after trimming, so accepting\n\t\t// one here mints a row that no memory operation can ever name again:\n\t\t// enumerable by List forever, unrecallable, unforgettable, reachable\n\t\t// only through `bd config unset` on the raw storage key. The HTTP\n\t\t// surface inherits the same split, so POST would accept what GET and\n\t\t// DELETE refuse.\n\t\t//\n\t\t// Surrounding space is still preserved on keys that survive this: the\n\t\t// rule is that a key must NAME something, not that it must be tidy.\n\t\treturn ValidateKey(key)\n\t}\n\tderived := DeriveKey(content)\n\tif derived == \"\" {\n\t\treturn \"\", fmt.Errorf(\"%w: could not generate key from content; use --key to specify one\", memoryops.ErrValidation)\n\t}\n\treturn derived, nil\n}\n\n// FilterMemories narrows already-prefix-stripped memories by a raw search term.\n//\n// THE FOLDING IS HERE, on both sides. The shipped `bd memories` lowercased the\n// term at the front door and the filter lowercased the stored values, which\n// worked only for as long as every caller remembered the first half; a second\n// door that passed the term through raw would have matched nothing and reported\n// an empty plane. Now the caller passes what the user typed.\n//\n// The answer is a fresh map, never nil and never the argument: a caller holding\n// the full plane must still hold it after asking a narrower question.\nfunc FilterMemories(all map[string]string, search string) map[string]string {\n\tif search == \"\" {\n\t\tout := make(map[string]string, len(all))\n\t\tfor k, v := range all {","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/memoryapi/memoryapi.go#L111-L147","documentation":"ResolveKey could not derive a key from the memory content (DeriveKey returned empty) and the caller supplied no usable explicit key. Since every memory must live under some key, it fails with memoryops.ErrValidation telling the user to pass --key. This happens when the content yields no derivable key material.","triggerScenarios":"Calling ResolveKey with no explicit key and content whose DeriveKey result is \"\"; ResolveKey with an explicit key that itself fails ValidateKey (blank), leaving the derivation path to fail.","commonSituations":"Content that DeriveKey cannot reduce to a key (degenerate/whitespace-normalized input); forgetting --key on bd remember for content that resists key derivation; whitespace-only explicit key falling through to derivation.","solutions":["Pass an explicit --key when storing the memory.","Ensure the content contains usable text from which a key can be derived.","Handle the ErrValidation by re-prompting for content or key."],"exampleFix":"// before\nbd remember \"...\" // fails: could not generate key\n// after\nbd remember \"...\" --key my-note-key","handlingStrategy":"validation","validationCode":"if strings.TrimSpace(content) == \"\" || (explicitKey != \"\" && strings.TrimSpace(explicitKey) == \"\") {\n    return fmt.Errorf(\"provide non-empty content and, if needed, an explicit --key\")\n}","typeGuard":null,"tryCatchPattern":"key, err := memoryapi.ResolveKey(content, explicitKey)\nif err != nil {\n    if errors.Is(err, memoryops.ErrValidation) {\n        return fmt.Errorf(\"retry with --key set\")\n    }\n    return err\n}","preventionTips":["Pass --key explicitly for content that may resist derivation.","Ensure memory content has substantive text.","Wrap ResolveKey with a prompt fallback in interactive tools."],"tags":["validation","memory","key-derivation"],"backgroundTag":"key-derivation-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}