{"record":{"id":"8d9935a0b153b307","repo":"Tencent/WeKnora","slug":"empty-result","errorCode":null,"errorMessage":"empty result","messagePattern":"empty result","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/agent/tools/scope_authorization.go","lineNumber":75,"sourceCode":"// decoding is necessary but never sufficient: the durable document must also\n// belong to the server-owned search scope for this Agent execution.\nfunc authorizeKnowledgeInSearchTargets(\n\tctx context.Context,\n\tsearchTargets types.SearchTargets,\n\tknowledgeID string,\n\tknowledgeService interfaces.KnowledgeService,\n) (*types.Knowledge, error) {\n\tknowledgeID = strings.TrimSpace(knowledgeID)\n\tif knowledgeID == \"\" {\n\t\treturn nil, fmt.Errorf(\"knowledge_id is required\")\n\t}\n\tif knowledgeService == nil {\n\t\treturn nil, fmt.Errorf(\"knowledge service is unavailable\")\n\t}\n\tknowledge, err := knowledgeService.GetKnowledgeByIDOnly(ctx, knowledgeID)\n\tif err != nil || knowledge == nil {\n\t\tif err == nil {\n\t\t\terr = fmt.Errorf(\"empty result\")\n\t\t}\n\t\treturn nil, fmt.Errorf(\"document %s not found: %w\", knowledgeID, err)\n\t}\n\tif !searchTargets.ContainsKB(knowledge.KnowledgeBaseID) {\n\t\treturn nil, fmt.Errorf(\"knowledge base %s is not within the current Agent scope\", knowledge.KnowledgeBaseID)\n\t}\n\tallowed, err := searchTargetsAllowKnowledgeID(\n\t\tctx, searchTargets, knowledge.ID, knowledge.KnowledgeBaseID, knowledgeService,\n\t)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to validate document scope: %w\", err)\n\t}\n\tif !allowed {\n\t\treturn nil, fmt.Errorf(\"document %s is not within the current @mention scope\", knowledge.ID)\n\t}\n\treturn knowledge, nil\n}\n","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/agent/tools/scope_authorization.go#L57-L93","documentation":"Sentinel inner error produced when GetKnowledgeByIDOnly returns no error but a nil Knowledge: the storage layer 'succeeded' with an empty result, so this guard substitutes a non-nil error so the caller's not-found wrapping has something to chain.","triggerScenarios":"Thrown at internal/agent/tools/scope_authorization.go:75 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Treat as 'document does not exist' and handle the not-found path","Verify the knowledge_id spelling","Ensure the storage layer returns a typed not-found error instead of nil,nil"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}