{"record":{"id":"cbfc948f00a54111","repo":"router-for-me/CLIProxyAPI","slug":"failed-to-update-source-auth-file-w","errorCode":null,"errorMessage":"failed to update source auth file: %w","messagePattern":"failed to update source auth file: %w","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"internal/api/handlers/management/auth_files_fields.go","lineNumber":134,"sourceCode":"\n// patchPluginVirtualSourceStatus toggles disabled on a plugin multi-auth source file and all\n// runtime auths expanded from it. Virtual project children cannot be toggled independently.\nfunc (h *Handler) patchPluginVirtualSourceStatus(ctx context.Context, targetAuth *coreauth.Auth, disabled bool) error {\n\tif h == nil || h.authManager == nil || targetAuth == nil {\n\t\treturn fmt.Errorf(\"core auth manager unavailable\")\n\t}\n\tsourcePath := strings.TrimSpace(authAttribute(targetAuth, coreauth.AttributeVirtualSource))\n\tif sourcePath == \"\" {\n\t\tsourcePath = strings.TrimSpace(authAttribute(targetAuth, \"path\"))\n\t}\n\tif sourcePath == \"\" {\n\t\treturn errPluginVirtualAuth\n\t}\n\tif errWrite := setSourceAuthFileDisabled(sourcePath, disabled); errWrite != nil {\n\t\tif os.IsNotExist(errWrite) {\n\t\t\treturn errAuthFileNotFound\n\t\t}\n\t\treturn fmt.Errorf(\"failed to update source auth file: %w\", errWrite)\n\t}\n\tnow := time.Now()\n\tfor _, auth := range h.authManager.List() {\n\t\tif auth == nil {\n\t\t\tcontinue\n\t\t}\n\t\tif !sameAuthFilePath(authAttribute(auth, \"path\"), sourcePath) &&\n\t\t\t!sameAuthFilePath(authAttribute(auth, coreauth.AttributeVirtualSource), sourcePath) {\n\t\t\tcontinue\n\t\t}\n\t\tapplyAuthDisabledState(auth, disabled)\n\t\tauth.UpdatedAt = now\n\t\tif _, errUpdate := h.authManager.Update(ctx, auth); errUpdate != nil {\n\t\t\treturn fmt.Errorf(\"failed to update auth %s: %w\", auth.ID, errUpdate)\n\t\t}\n\t}\n\treturn nil\n}","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/router-for-me/CLIProxyAPI/blob/78f0c4079e3e6273d65d03b5549cffc898703264/internal/api/handlers/management/auth_files_fields.go#L116-L152","documentation":"setSourceAuthFileDisabled failed while reading, parsing, or writing the plugin source auth file to flip its disabled flag, and the error was not os.IsNotExist. The %w wrap carries the real fs error — typically a permission failure on read or on the 0600 write, or a read-only filesystem issue.","triggerScenarios":"PATCH toggle of a plugin multi-auth source where the file or its directory is read-only or owned by another user; auth dir mounted read-only (container volume with wrong mode); disk full causing the write to fail; SELinux/AppArmor denying the write.","commonSituations":"Running the proxy in Docker with a bind-mounted auths/ volume owned by root while the process runs non-root; a hardened or immutable container filesystem; files created by a previously different service user.","solutions":["Check the wrapped cause: permission denied → chown/chmod the file and auth dir for the service user","If the auth dir is mounted read-only, remount it rw or point auth-dir at a writable location","Verify disk space and filesystem health (df -h, dmesg for I/O errors)","Retry the PATCH after fixing the underlying fs issue"],"exampleFix":"# before\ndocker run -v ./auths:/app/auths:ro ...\n# after\ndocker run -v ./auths:/app/auths rw, after chown -R appuser:appuser ./auths","handlingStrategy":"try-catch","validationCode":"if info, err := os.Stat(sourcePath); err != nil {\n    return err\n} else if info.Mode().Perm()&0o200 == 0 {\n    return errors.New(\"auth file not writable\")\n}","typeGuard":null,"tryCatchPattern":"if err := patchPluginVirtualSourceStatus(ctx, auth, disabled); err != nil {\n    if os.IsPermission(errors.Unwrap(err)) { /* fix ownership, then retry once */ }\n    return err\n}","preventionTips":["Make the auth dir writable by the service user in containers","Mount auth volumes rw, never ro","Periodically verify file ownership after deploy tooling runs"],"tags":["filesystem","permissions","auth","docker"],"backgroundTag":null,"analyzedSha":"78f0c4079e3e6273d65d03b5549cffc898703264","analyzedAt":"2026-08-15T12:26:37.444Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}