{"record":{"id":"d55b41b6ea7b4175","repo":"Billionmail/BillionMail","slug":"error-reading-knowledge-base-v","errorCode":null,"errorMessage":"error reading knowledge base: %v","messagePattern":"error reading knowledge base: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/internal/service/askai/project.go","lineNumber":384,"sourceCode":"\t\tTid = GetUUID()\n\t}\n\n\tknowledge := KnowledgeInfo{\n\t\tKid:        Tid,\n\t\tTitle:      Title,\n\t\tContent:    Content,\n\t\tUpdateTime: public.GetNowTime(),\n\t}\n\treturn SaveKnowledgeBase(Domain, knowledge)\n}\n\n// ModifyKnowledgeBaseFile updates the title and content of an existing knowledge base file.\n// It reads the existing knowledge base, modifies the specified fields, and saves the updated knowledge base.\n// If the knowledge base does not exist or cannot be read, it returns an error.\nfunc ModifyKnowledgeBaseFile(Domain string, Kid string, Title string, Content string) error {\n\tknowledge, err := ReadKnowledgeBase(Domain, Kid)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error reading knowledge base: %v\", err)\n\t}\n\n\t// Update the knowledge base information\n\tif Title != \"\" {\n\t\tknowledge.Title = Title\n\t}\n\tif Content != \"\" {\n\t\tknowledge.Content = Content\n\t}\n\n\tknowledge.UpdateTime = public.GetNowTime()\n\terr = SaveKnowledgeBase(Domain, knowledge)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error saving knowledge base: %v\", err)\n\t}\n\treturn nil\n}\n","sourceCodeStart":366,"sourceCodeEnd":402,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/service/askai/project.go#L366-L402","documentation":"ModifyKnowledgeBaseFile first loads the existing knowledge base via ReadKnowledgeBase before applying updates. This error wraps any failure from that read: the file does not exist, cannot be read, or contains invalid JSON. It means the knowledge base identified by (Domain, Kid) could not be loaded, so no modification occurred.","triggerScenarios":"ReadKnowledgeBase(Domain, Kid) returns an error because: no file exists at PRODUCT_CONFIG_PATH/<domain>/knowledge/<kid>.json (wrong Kid, wrong domain, or entry was deleted); the file is unreadable due to permissions; the JSON content is corrupt and fails to unmarshal (the inner 'error unmarshalling knowledge base').","commonSituations":"Client passes a stale Kid after the knowledge base was deleted; Kid casing or truncation mismatch (e.g. Kid derived from a filename split on '.'); domain mismatch between create and modify calls; file edited externally with invalid JSON.","solutions":["Verify the Kid matches an existing file: list PRODUCT_CONFIG_PATH/<domain>/knowledge/ and confirm <kid>.json exists","Confirm the same Domain string is used for create, list, and modify calls","If the file is corrupt, restore valid JSON or delete and recreate the knowledge base via CreateKnowledgeBaseFile","Check file read permissions on the JSON file"],"exampleFix":"// before\nModifyKnowledgeBaseFile(domain, kid, title, content) // kid from stale cache\n// after\nif err := KnowledgeBaseExists(domain, kid); err != nil {\n    return CreateKnowledgeBaseFile(domain, title, content, kid) // recreate if missing\n}\nreturn ModifyKnowledgeBaseFile(domain, kid, title, content)","handlingStrategy":"validation","validationCode":"func knowledgeBaseExists(domain, kid string) bool {\n    return public.FileExists(fmt.Sprintf(PRODUCT_CONFIG_PATH+\"/%s/knowledge/%s.json\", domain, kid))\n}\n// before ModifyKnowledgeBaseFile:\nif !knowledgeBaseExists(domain, kid) {\n    return fmt.Errorf(\"knowledge base %s not found for %s\", kid, domain)\n}","typeGuard":null,"tryCatchPattern":"if err := ModifyKnowledgeBaseFile(domain, kid, title, content); err != nil {\n    if strings.Contains(err.Error(), \"reading knowledge base\") {\n        // treat as not-found: surface 404 to caller or recreate\n    }\n}","preventionTips":["Fetch the current list (GetKnowledgeBaseList) before editing so Kid values are fresh","Keep a single source of truth for Domain strings (no case/whitespace drift)","Validate Kid format (UUID) client-side before calls","Avoid externally editing knowledge JSON files with non-conforming tools"],"tags":["go","filesystem","json","not-found"],"backgroundTag":"config-file-not-found","analyzedSha":"fc36c76c050c3775c5e899faf7403cf0262d2744","analyzedAt":"2026-09-05T21:28:54.019Z","contentChangedAt":"2026-09-05T21:28:54.019Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}