{"record":{"id":"4ee2ea159bf595ea","repo":"chenhg5/cc-connect","slug":"directory-reference-cannot-carry-a-location","errorCode":null,"errorMessage":"directory reference cannot carry a location","messagePattern":"directory reference cannot carry a location","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/reference_show.go","lineNumber":41,"sourceCode":"\treferenceViewRange    referenceViewMode = \"range\"\n\treferenceViewDir      referenceViewMode = \"dir\"\n)\n\ntype referenceViewRequest struct {\n\tRef        *localReference\n\tMode       referenceViewMode\n\tWindow     int\n\tMaxLines   int\n\tMaxEntries int\n}\n\nfunc buildReferenceViewRequest(rawRef, workspaceDir string) (*referenceViewRequest, error) {\n\tref, err := parseUserLocalReference(rawRef, workspaceDir)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif ref.kind == referenceKindDir && ref.locationFormat != referenceLocationNone {\n\t\treturn nil, fmt.Errorf(\"directory reference cannot carry a location\")\n\t}\n\treq := &referenceViewRequest{\n\t\tRef:        ref,\n\t\tWindow:     defaultShowContextLines,\n\t\tMaxLines:   defaultShowMaxRange,\n\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}","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/core/reference_show.go#L23-L59","documentation":"`buildReferenceViewRequest` rejects a reference that resolves to a directory but also specifies a line/window location (`ref.locationFormat != referenceLocationNone`), since a directory listing has no line-addressable content. The error prevents rendering a file-style view (head + context lines) for something that can only be listed.","triggerScenarios":"Calling buildReferenceViewRequest (via cmdShow or the anonymous message handler) with a directory path carrying a location suffix — e.g. `src/:10`, `src/utils:42-50`, or a markdown link to a directory with a line suffix.","commonSituations":"User types `/show src/` then drags/selects text adding `:12`; a card template appends the current line number to a directory reference; scripts that programmatically append `:N` to any path, including directories.","solutions":["Drop the location suffix when referencing a directory: use `/show src/` instead of `/show src/:10`.","Check with os.Stat whether the target is a directory before appending a line suffix.","If the intent is a specific file inside the directory, name the file: `/show src/main.go:10`.","Fix any automation that unconditionally appends `:<line>` to reference strings."],"exampleFix":"// before\nreq, err := buildReferenceViewRequest(\"src/:10\", workspaceDir)\n\n// after\nif info, err := os.Stat(filepath.Join(workspaceDir, \"src\")); err == nil && info.IsDir() {\n    req, err = buildReferenceViewRequest(\"src/\", workspaceDir) // no :line\n} else {\n    req, err = buildReferenceViewRequest(\"src/:10\", workspaceDir)\n}","handlingStrategy":"validation","validationCode":"func stripLocationIfDir(raw, workspaceDir string) string {\n    base := raw\n    if i := strings.LastIndex(base, \":\"); i > 0 { base = base[:i] }\n    if info, err := os.Stat(filepath.Join(workspaceDir, base)); err == nil && info.IsDir() {\n        return base\n    }\n    return raw\n}","typeGuard":null,"tryCatchPattern":"req, err := buildReferenceViewRequest(rawRef, ws)\nif err != nil && strings.Contains(err.Error(), \"directory reference\") {\n    reply(\"directories cannot take :line — try /show \" + strings.TrimSuffix(rawRef, \":\"+linePart))\n    return\n}","preventionTips":["Never append a :line suffix to paths that may be directories.","Stat the target and strip the location when it is a directory.","Show a targeted usage hint when this error is returned to the user."],"tags":["validation","arguments","filesystem","go"],"backgroundTag":"invalid-argument-value","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"}