{"record":{"id":"1fb6d9dd3a433cd6","repo":"chenhg5/cc-connect","slug":"read-sessions-dir-w","errorCode":null,"errorMessage":"read sessions dir: %w","messagePattern":"read sessions dir: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cc-connect/sessions.go","lineNumber":158,"sourceCode":"\nfunc resolveDataDir(flagValue string) string {\n\tif flagValue != \"\" {\n\t\treturn flagValue\n\t}\n\tif home, err := os.UserHomeDir(); err == nil {\n\t\treturn filepath.Join(home, \".cc-connect\")\n\t}\n\treturn \".cc-connect\"\n}\n\nfunc loadAllSessions(dataDir string) ([]sessionRecord, error) {\n\tsessionsDir := filepath.Join(dataDir, \"sessions\")\n\tentries, err := os.ReadDir(sessionsDir)\n\tif err != nil {\n\t\tif os.IsNotExist(err) {\n\t\t\treturn nil, nil\n\t\t}\n\t\treturn nil, fmt.Errorf(\"read sessions dir: %w\", err)\n\t}\n\n\tvar records []sessionRecord\n\tfor _, entry := range entries {\n\t\tif entry.IsDir() || !strings.HasSuffix(entry.Name(), \".json\") {\n\t\t\tcontinue\n\t\t}\n\n\t\tproject := strings.TrimSuffix(entry.Name(), \".json\")\n\t\tfilePath := filepath.Join(sessionsDir, entry.Name())\n\n\t\tdata, err := os.ReadFile(filePath)\n\t\tif err != nil {\n\t\t\tfmt.Fprintf(os.Stderr, \"Warning: cannot read %s: %v\\n\", entry.Name(), err)\n\t\t\tcontinue\n\t\t}\n\n\t\tvar fileData sessionFileData","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/cmd/cc-connect/sessions.go#L140-L176","documentation":"loadAllSessions reads <dataDir>/sessions to enumerate session records for `cc-connect sessions list/show`. A missing directory returns (nil, nil) intentionally (no sessions yet), but any other ReadDir failure (permissions, I/O) aborts with this wrapped error rather than showing a possibly-empty list.","triggerScenarios":"Running `cc-connect sessions list` or `sessions show` when the sessions directory exists but cannot be read: wrong ownership/permissions or a filesystem I/O error.","commonSituations":"Custom --data-dir pointing at a directory owned by another user, restored data with bad ownership, failing disk/network mount.","solutions":["Fix permissions on <dataDir>/sessions: `chmod 755` and chown to the running user","Verify the --data-dir value points at the directory cc-connect actually wrote","If the error is I/O (EIO), check disk/mount health"],"exampleFix":"// before\ndrwx------ root root ~/.local/share/cc-connect/sessions\n// after\nchown -R $USER ~/.local/share/cc-connect && chmod 755 ~/.local/share/cc-connect/sessions","handlingStrategy":"validation","validationCode":"dir=~/.local/share/cc-connect/sessions; [ -r \"$dir\" ] || { echo \"unreadable or missing: $dir\" >&2; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep dataDir owned by the cc-connect user","Double-check --data-dir overrides in scripts and service units","Include a directory readability check in deployment scripts"],"tags":["cli","sessions","permissions","filesystem"],"backgroundTag":"directory-not-found","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"}