{"record":{"id":"666ef5790a9a0b6d","repo":"chenhg5/cc-connect","slug":"nil-view-request","errorCode":null,"errorMessage":"nil view request","messagePattern":"nil view request","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/reference_show.go","lineNumber":65,"sourceCode":"\t\tMaxEntries: defaultShowMaxEntries,\n\t}\n\tswitch {\n\tcase ref.kind == referenceKindDir:\n\t\treq.Mode = referenceViewDir\n\tcase ref.locationFormat == referenceLocationColonRange:\n\t\treq.Mode = referenceViewRange\n\tcase ref.locationFormat != referenceLocationNone:\n\t\treq.Mode = referenceViewContext\n\tdefault:\n\t\treq.Mode = referenceViewFileHead\n\t\treq.MaxLines = defaultShowHeadLines\n\t}\n\treturn req, nil\n}\n\nfunc renderReferenceView(req *referenceViewRequest) (string, error) {\n\tif req == nil || req.Ref == nil {\n\t\treturn \"\", fmt.Errorf(\"nil view request\")\n\t}\n\tpath := req.Ref.pathAbs\n\tif path == \"\" {\n\t\tpath = req.Ref.pathOriginal\n\t}\n\tif path == \"\" {\n\t\treturn \"\", fmt.Errorf(\"empty path\")\n\t}\n\tinfo, err := os.Stat(path)\n\tif err != nil {\n\t\tif os.IsNotExist(err) {\n\t\t\treturn \"\", fmt.Errorf(\"path does not exist\")\n\t\t}\n\t\treturn \"\", err\n\t}\n\tif info.IsDir() {\n\t\tif req.Ref.locationFormat != referenceLocationNone {\n\t\t\treturn \"\", fmt.Errorf(\"directory reference cannot carry a location\")","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/core/reference_show.go#L47-L83","documentation":"renderReferenceView validates that the caller passed a fully constructed *referenceViewRequest containing a non-nil Ref before rendering. A nil request or nil Ref means no reference was ever parsed/attached, so there is nothing to display. This is an internal invariant guard against programming mistakes upstream.","triggerScenarios":"Calling renderReferenceView (directly in tests, or via cmdShow) with a nil *referenceViewRequest, or with a request struct whose Ref field was never populated by the reference parser.","commonSituations":"Test code constructing referenceViewRequest by hand and forgetting to set Ref; a refactor of the request-building code that skips Ref population on an error path; calling cmdShow with a message that yielded no reference but the code path still proceeds to render.","solutions":["Inspect how the referenceViewRequest is built before renderReferenceView is called and ensure buildReferenceViewRequest succeeded and returned a non-nil Ref","In tests, populate req.Ref with a valid reference struct (e.g. via the reference parser) instead of passing a zero-value or nil request","Wrap the call: only invoke renderReferenceView if req != nil && req.Ref != nil"],"exampleFix":"// before\nout, err := renderReferenceView(req)\n// after\nif req == nil || req.Ref == nil {\n    return \"\", fmt.Errorf(\"show: no reference parsed\")\n}\nout, err := renderReferenceView(req)","handlingStrategy":"type-guard","validationCode":"if req == nil || req.Ref == nil {\n    return \"\", fmt.Errorf(\"no reference parsed\")\n}","typeGuard":"func hasRef(req *referenceViewRequest) bool { return req != nil && req.Ref != nil }","tryCatchPattern":"out, err := renderReferenceView(req)\nif err != nil {\n    if strings.Contains(err.Error(), \"nil view request\") {\n        // handle missing reference: reply with usage hint\n        return \"\", nil\n    }\n    return \"\", err\n}","preventionTips":["Always build requests through the shared request-builder instead of struct literals","Add a unit test asserting the parser never returns a request with nil Ref on success","Run go vet / nilness linters to catch unchecked nil flows"],"tags":["go","nil-pointer","internal-invariant"],"backgroundTag":"null-argument","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}