chenhg5/cc-connect · error

create temp config: %w

Error message

create temp config: %w

What it means

saveConfig writes atomically by creating a temporary file (os.CreateTemp) in the config directory before renaming it into place. If the temp file cannot be created — directory missing, no write permission, disk full — it returns this wrapped error and nothing is modified.

Source

Thrown at config/config.go:1549

	if ConfigPath == "" {
		return nil, fmt.Errorf("config path not set")
	}
	data, err := os.ReadFile(ConfigPath)
	if err != nil {
		return nil, fmt.Errorf("read config: %w", err)
	}
	cfg := &Config{}
	if err := toml.Unmarshal(data, cfg); err != nil {
		return nil, fmt.Errorf("parse config: %w", err)
	}
	return cfg, nil
}

func saveConfig(cfg *Config) error {
	dir := filepath.Dir(ConfigPath)
	tmp, err := os.CreateTemp(dir, ".config-*.tmp")
	if err != nil {
		return fmt.Errorf("create temp config: %w", err)
	}
	tmpPath := tmp.Name()

	var buf strings.Builder
	if err := toml.NewEncoder(&buf).Encode(cfg); err != nil {
		tmp.Close()
		os.Remove(tmpPath)
		return fmt.Errorf("encode config: %w", err)
	}

	formatted := formatTOML(buf.String())
	if _, err := tmp.WriteString(formatted); err != nil {
		tmp.Close()
		os.Remove(tmpPath)
		return fmt.Errorf("write config: %w", err)
	}
	if err := tmp.Sync(); err != nil {
		tmp.Close()

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Create the config directory first: os.MkdirAll(filepath.Dir(ConfigPath), 0o755).
  2. Check directory permissions so the running user can write (chown/chmod).
  3. Verify free disk space / quota and that the filesystem is mounted writable.

Example fix

// before
err := config.UpdateGlobalProvider("anthropic", p)
// after
os.MkdirAll(filepath.Dir(config.ConfigPath), 0o755)
err := config.UpdateGlobalProvider("anthropic", p)
Defensive patterns

Strategy: validation

Validate before calling

dir := filepath.Dir(config.ConfigPath)
if fi, err := os.Stat(dir); err != nil || !fi.IsDir() {
    if err := os.MkdirAll(dir, 0o755); err != nil {
        return err
    }
}
if err := syscall.Access(dir, syscall.O_RDWR); err != nil {
    return fmt.Errorf("config dir not writable: %w", err)
}

Try / catch

if err := config.UpdateGlobalProvider(name, p); err != nil {
    if strings.Contains(err.Error(), "create temp config") {
        os.MkdirAll(filepath.Dir(config.ConfigPath), 0o755)
        return config.UpdateGlobalProvider(name, p) // retry
    }
    return err
}

Prevention

When it happens

Trigger: os.CreateTemp(filepath.Dir(ConfigPath), ".config-*.tmp") fails: the config directory does not exist, the process lacks write permission on it, or the filesystem is read-only/full.

Common situations: Fresh install where ~/.config/cc-connect/ was never created; running the daemon as a system user while the config lives in a human user's home; read-only container root filesystem; disk quota exceeded.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


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