{"record":{"id":"2f7e7578e777844e","repo":"Tencent/WeKnora","slug":"wiki-graph-request-is-required","errorCode":null,"errorMessage":"wiki graph request is required","messagePattern":"wiki graph request is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/application/service/wiki_page.go","lineNumber":578,"sourceCode":"//     node in the overview.\n//\n// `Types` is an optional page_type allow-list applied to both the candidate\n// node set and (in ego mode) the frontier expansion. Leaving it empty means\n// no type filter.\n//\n// `Limit <= 0` disables the cap entirely and is reserved for internal\n// callers like the lint service that need to walk every page. The HTTP\n// handler always clamps Limit into a safe range so external traffic can\n// never opt out of truncation.\n//\n// Implementation note: pages are still fetched via repo.ListAll. At 4万\n// pages that's ~10MB of rows + deserialization, which is already on the\n// expensive side but still tractable and keeps the repository interface\n// unchanged. Pushing the filter/top-N down into SQL is a follow-up step\n// (cache layer + DB-side projection) — see CLAUDE.md plan.\nfunc (s *wikiPageService) GetGraph(ctx context.Context, req *types.WikiGraphRequest) (*types.WikiGraphData, error) {\n\tif req == nil {\n\t\treturn nil, errors.New(\"wiki graph request is required\")\n\t}\n\n\tpages, err := s.repo.ListAll(ctx, req.KnowledgeBaseID)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn computeGraphSubset(pages, req)\n}\n\n// computeGraphSubset is the pure I/O-free core of GetGraph. It takes the\n// full page list and a request description and returns the subgraph the\n// caller asked for. Extracted from GetGraph so tests can exercise the\n// mode/limit/type-filter behavior without plumbing a full repository mock.\nfunc computeGraphSubset(pages []*types.WikiPage, req *types.WikiGraphRequest) (*types.WikiGraphData, error) {\n\tmode := req.Mode\n\tif mode == \"\" {\n\t\tmode = types.WikiGraphModeOverview\n\t}","sourceCodeStart":560,"sourceCodeEnd":596,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/wiki_page.go#L560-L596","documentation":"GetGraph requires a WikiGraphRequest; when the request pointer is nil the service returns this error. Building the wiki graph needs the KnowledgeBaseID (and filter/top-N settings) from the request, so a nil request is unusable. This is a defensive nil-check before any repository work.","triggerScenarios":"Calling GetGraph(ctx, nil) — e.g. a handler that failed to decode/bind the request body but continued, or internal callers constructing the request conditionally.","commonSituations":"Handler skips JSON body decoding error handling and passes a nil struct; internal code paths building requests dynamically that end up unset; tests invoking the service without a request object.","solutions":["Always construct and pass a WikiGraphRequest (at minimum with KnowledgeBaseID) to GetGraph.","Fix the handler to return 400 on body decode failure instead of passing a nil request.","Add a nil check at the caller level before invoking the service."],"exampleFix":"// before\nvar req *types.WikiGraphRequest\nif err := c.ShouldBindJSON(&req); err != nil { /* ignored */ }\ndata, err := h.svc.GetGraph(ctx, req)\n// after\nvar req types.WikiGraphRequest\nif err := c.ShouldBindJSON(&req); err != nil {\n    return httpError(400, \"invalid request\")\n}\ndata, err := h.svc.GetGraph(ctx, &req)","handlingStrategy":"validation","validationCode":"if req == nil {\n    return httpError(400, \"wiki graph request is required\")\n}","typeGuard":"func validGraphRequest(r *types.WikiGraphRequest) bool {\n    return r != nil && strings.TrimSpace(r.KnowledgeBaseID) != \"\"\n}","tryCatchPattern":null,"preventionTips":["Return 400 on request body decode errors instead of continuing with a nil struct.","Validate the decoded request (non-nil, KB id set) before calling the service.","Pass requests by value where practical to eliminate nil-pointer states."],"tags":["validation","nil-check","wiki","missing-argument"],"backgroundTag":"nil-request-payload","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}