{"record":{"id":"b1d534e97816b69c","repo":"chenhg5/cc-connect","slug":"cannot-parse-local-reference","errorCode":null,"errorMessage":"cannot parse local reference","messagePattern":"cannot parse local reference","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/reference_parse.go","lineNumber":66,"sourceCode":"\treColonLineRange = regexp.MustCompile(`^(.*):(\\d+)-(\\d+)$`)\n\treColonLineOnly  = regexp.MustCompile(`^(.*):(\\d+)$`)\n)\n\nfunc parseUserLocalReference(raw, workspaceDir string) (*localReference, error) {\n\traw = strings.TrimSpace(raw)\n\tif raw == \"\" {\n\t\treturn nil, fmt.Errorf(\"empty reference\")\n\t}\n\tif match := reMarkdownLink.FindStringSubmatch(raw); len(match) >= 3 && match[0] == raw {\n\t\tsuffix := \"\"\n\t\tif len(match) >= 4 {\n\t\t\tsuffix = match[3]\n\t\t}\n\t\traw = match[2] + suffix\n\t}\n\tref, ok := parseLocalReference(raw, workspaceDir)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"cannot parse local reference\")\n\t}\n\treturn ref, nil\n}\n\nfunc parseLocalReference(raw, workspaceDir string) (*localReference, bool) {\n\traw = strings.TrimSpace(raw)\n\tif raw == \"\" || isWebURL(raw) || strings.HasPrefix(raw, \"//\") {\n\t\treturn nil, false\n\t}\n\tref := &localReference{raw: raw}\n\tpathPart := raw\n\tswitch {\n\tcase reHashLocation.MatchString(pathPart):\n\t\tm := reHashLocation.FindStringSubmatch(pathPart)\n\t\tpathPart = m[1]\n\t\tref.lineStart = atoiSafe(m[3])\n\t\tref.column = atoiSafe(m[4])\n\t\tif ref.column > 0 {","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/core/reference_parse.go#L48-L84","documentation":"After stripping a markdown-link wrapper, `parseUserLocalReference` delegates to `parseLocalReference`; if that returns `ok == false` the input matched no accepted local-reference form, so it fails with `cannot parse local reference`. The library only accepts workspace-relative paths (optionally with :line suffixes) and plain/markdown-link forms.","triggerScenarios":"Calling parseUserLocalReference with a string that is neither a valid file/dir path in workspaceDir nor a markdown link — absolute paths outside the workspace it rejects, URLs like https://..., glob patterns, or nonexistent files, depending on parseLocalReference's rules.","commonSituations":"User pastes a full external URL into `/show`; the referenced file does not exist or lies outside workspaceDir; the path uses backslashes on a workspace resolved with forward slashes; typos in the filename.","solutions":["Pass a plain workspace-relative path that exists (e.g. `core/engine.go` or `core/engine.go:42`).","Verify the file exists: `os.Stat(filepath.Join(workspaceDir, raw))` before calling.","If referencing a file outside workspaceDir, either move/symlink it into the workspace or use the supported reference form.","Convert external URLs/attachments to a downloaded local file path first, then reference that path."],"exampleFix":"// before\nreq, err := buildReferenceViewRequest(\"https://example.com/foo.go\", workspaceDir)\n\n// after\np := \"foo.go\" // after downloading the remote file into the workspace\nif _, err := os.Stat(filepath.Join(workspaceDir, p)); err != nil {\n    reply(\"file not found in workspace: \" + p)\n    return\n}\nreq, err := buildReferenceViewRequest(p, workspaceDir)","handlingStrategy":"validation","validationCode":"func referenceExists(raw, workspaceDir string) bool {\n    p := filepath.Join(workspaceDir, filepath.FromSlash(strings.TrimSpace(raw)))\n    _, err := os.Stat(p)\n    return err == nil\n}","typeGuard":null,"tryCatchPattern":"req, err := buildReferenceViewRequest(rawRef, ws)\nif err != nil {\n    reply(fmt.Sprintf(\"cannot open %q — use a workspace-relative path like core/engine.go[:line]\", rawRef))\n    return\n}","preventionTips":["Document the accepted reference syntax (workspace-relative path, optional :line).","Stat the resolved path before requesting a view to give a precise 'file not found' hint.","Normalize backslash paths to forward slashes on Windows workspaces.","Reject or download external URLs before they reach the reference parser."],"tags":["parsing","validation","filesystem","go"],"backgroundTag":"invalid-argument-format","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"}