{"record":{"id":"9e7c8d9cf6f9236b","repo":"chenhg5/cc-connect","slug":"save-config-w","errorCode":null,"errorMessage":"save config: %w","messagePattern":"save config: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/config.go","lineNumber":3966,"sourceCode":"\t\tchanged = true\n\t}\n\tif !bridgeEnabled {\n\t\tcfg.Bridge.Enabled = &t\n\t\tif cfg.Bridge.Port == 0 {\n\t\t\tcfg.Bridge.Port = 9810\n\t\t}\n\t\tif cfg.Bridge.Token == \"\" {\n\t\t\tcfg.Bridge.Token = bridgeToken\n\t\t}\n\t\tif len(cfg.Bridge.CORSOrigins) == 0 {\n\t\t\tcfg.Bridge.CORSOrigins = []string{\"*\"}\n\t\t}\n\t\tchanged = true\n\t}\n\n\tif changed {\n\t\tif err := saveConfig(cfg); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"save config: %w\", err)\n\t\t}\n\t}\n\n\treturn &WebSetupResult{\n\t\tManagementPort:  orDefault(cfg.Management.Port, 9820),\n\t\tManagementToken: cfg.Management.Token,\n\t\tBridgePort:      orDefault(cfg.Bridge.Port, 9810),\n\t\tBridgeToken:     cfg.Bridge.Token,\n\t\tAlreadyEnabled:  false,\n\t}, nil\n}\n\nfunc orDefault(v, d int) int {\n\tif v == 0 {\n\t\treturn d\n\t}\n\treturn v\n}","sourceCodeStart":3948,"sourceCodeEnd":3984,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/config/config.go#L3948-L3984","documentation":"After modifying the management/bridge sections, EnableWebAdmin persists the Config via saveConfig(cfg); a failure there is wrapped as \"save config: %w\". saveConfig typically serializes to TOML and writes the file, so this covers serialization errors and filesystem write/permission failures.","triggerScenarios":"The config directory or file is read-only (chmod/ownership problem); the filesystem is full or mounted read-only; TOML serialization of the modified Config fails; the process lacks write permission on config.toml (e.g. editing the file requires root).","commonSituations":"config.toml owned by root while the daemon runs as a normal user; ~/.config directory missing or not writable; disk quota exceeded; running the setup command without sudo against a system-wide config.","solutions":["Check and fix permissions: ensure the process user can write config.toml (chown/chmod 600, writable parent directory)","Free disk space / address read-only mount if the FS is full or ro","If root-owned, re-run setup with elevated privileges or transfer ownership: sudo chown $USER config.toml","Inspect the inner wrapped error from saveConfig to distinguish write vs serialization failure"],"exampleFix":"// before\nsudo cc-connect setup-web   # writes root-owned config\n// after\nsudo chown $USER ~/.cc-connect/config.toml && cc-connect setup-web","handlingStrategy":"try-catch","validationCode":"if fi, err := os.Stat(config.ConfigPath); err == nil {\n    if err := syscall.Access(config.ConfigPath, os.O_WRONLY); err != nil {\n        return fmt.Errorf(\"config.toml not writable by current user\")\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := config.EnableWebAdmin(t, b); err != nil {\n    if strings.Contains(err.Error(), \"save config\") {\n        slog.Error(\"could not persist config; check disk space and file ownership\", \"err\", err)\n    }\n    return err\n}","preventionTips":["Keep config.toml owned and writable by the daemon user","Monitor disk space where the config lives","Prefer re-running setup with correct privileges over sudo-copying root-owned files","Use atomic rename writes so partial saves never corrupt the file"],"tags":["config","file-io","permissions","go"],"backgroundTag":"file-write-failed","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"}