chenhg5/cc-connect · error

read sessions dir: %w

Error message

read sessions dir: %w

What it means

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.

Source

Thrown at cmd/cc-connect/sessions.go:158

func resolveDataDir(flagValue string) string {
	if flagValue != "" {
		return flagValue
	}
	if home, err := os.UserHomeDir(); err == nil {
		return filepath.Join(home, ".cc-connect")
	}
	return ".cc-connect"
}

func loadAllSessions(dataDir string) ([]sessionRecord, error) {
	sessionsDir := filepath.Join(dataDir, "sessions")
	entries, err := os.ReadDir(sessionsDir)
	if err != nil {
		if os.IsNotExist(err) {
			return nil, nil
		}
		return nil, fmt.Errorf("read sessions dir: %w", err)
	}

	var records []sessionRecord
	for _, entry := range entries {
		if entry.IsDir() || !strings.HasSuffix(entry.Name(), ".json") {
			continue
		}

		project := strings.TrimSuffix(entry.Name(), ".json")
		filePath := filepath.Join(sessionsDir, entry.Name())

		data, err := os.ReadFile(filePath)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Warning: cannot read %s: %v\n", entry.Name(), err)
			continue
		}

		var fileData sessionFileData

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Fix permissions on <dataDir>/sessions: `chmod 755` and chown to the running user
  2. Verify the --data-dir value points at the directory cc-connect actually wrote
  3. If the error is I/O (EIO), check disk/mount health

Example fix

// before
drwx------ root root ~/.local/share/cc-connect/sessions
// after
chown -R $USER ~/.local/share/cc-connect && chmod 755 ~/.local/share/cc-connect/sessions
Defensive patterns

Strategy: validation

Validate before calling

dir=~/.local/share/cc-connect/sessions; [ -r "$dir" ] || { echo "unreadable or missing: $dir" >&2; exit 1; }

Prevention

When it happens

Trigger: 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.

Common situations: Custom --data-dir pointing at a directory owned by another user, restored data with bad ownership, failing disk/network mount.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/1fb6d9dd3a433cd6. Report an issue: GitHub.