{"record":{"id":"5ab03b568e2cb265","repo":"router-for-me/CLIProxyAPI","slug":"auth-file-is-empty-for-auth-index-s","errorCode":null,"errorMessage":"auth file is empty for auth_index %s","messagePattern":"auth file is empty for auth_index (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/pluginhost/auth_callbacks.go","lineNumber":253,"sourceCode":"\nfunc (h *Host) authPhysicalJSONByIndex(authIndex string) (*coreauth.Auth, []byte, error) {\n\tauth, errGet := h.authByIndex(authIndex)\n\tif errGet != nil {\n\t\treturn nil, nil, errGet\n\t}\n\tpath := strings.TrimSpace(authAttribute(auth, \"path\"))\n\tif path == \"\" {\n\t\treturn nil, nil, fmt.Errorf(\"auth file path not found for auth_index %s\", authIndex)\n\t}\n\tdata, errRead := os.ReadFile(path)\n\tif errRead != nil {\n\t\tif os.IsNotExist(errRead) {\n\t\t\treturn nil, nil, fmt.Errorf(\"auth file not found for auth_index %s\", authIndex)\n\t\t}\n\t\treturn nil, nil, fmt.Errorf(\"failed to read auth file: %w\", errRead)\n\t}\n\tif len(bytesTrimSpace(data)) == 0 {\n\t\treturn nil, nil, fmt.Errorf(\"auth file is empty for auth_index %s\", authIndex)\n\t}\n\tvar metadata map[string]any\n\tif errUnmarshal := json.Unmarshal(data, &metadata); errUnmarshal != nil {\n\t\treturn nil, nil, fmt.Errorf(\"invalid auth file for auth_index %s: %w\", authIndex, errUnmarshal)\n\t}\n\treturn auth, data, nil\n}\n\nfunc validateHostAuthSaveRequest(req pluginapi.HostAuthSaveRequest) (string, []byte, error) {\n\tname := strings.TrimSpace(req.Name)\n\tif isUnsafeAuthFileName(name) {\n\t\treturn \"\", nil, fmt.Errorf(\"invalid auth file name\")\n\t}\n\tif !strings.HasSuffix(strings.ToLower(name), \".json\") {\n\t\treturn \"\", nil, fmt.Errorf(\"auth file name must end with .json\")\n\t}\n\trawJSON := bytesTrimSpace(req.JSON)\n\tif len(rawJSON) == 0 {","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/router-for-me/CLIProxyAPI/blob/78f0c4079e3e6273d65d03b5549cffc898703264/internal/pluginhost/auth_callbacks.go#L235-L271","documentation":"Thrown by Host.authPhysicalJSONByIndex when the auth file exists and is readable but contains only whitespace bytes (len(bytesTrimSpace(data)) == 0). An auth file must be a non-empty JSON object; an empty file is treated as corruption, not a valid empty state.","triggerScenarios":"Auth file truncated to zero bytes by a crash during write, a failed atomic replace, or manual editing; a file created by touch as a placeholder in the auths directory.","commonSituations":"Power loss / kill -9 during credential refresh leaving a zero-length file; deployment tooling creating empty placeholder files; editor saving an emptied file.","solutions":["Delete the empty file and re-run the provider's auth flow to regenerate it","If the content is known, restore it from backup","Use atomic write tooling (write temp + rename) when generating auth files to avoid truncation"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if info, err := os.Stat(path); err == nil && info.Size() == 0 {\n    // treat as corrupt; skip or regenerate before reading\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"auth file is empty\") {\n    // delete the file and re-run provider auth\n}","preventionTips":["Generate auth files with write-temp-then-rename","Monitor auths/ for zero-length files after crashes"],"tags":["go","pluginhost","auth","filesystem","corruption"],"backgroundTag":null,"analyzedSha":"78f0c4079e3e6273d65d03b5549cffc898703264","analyzedAt":"2026-08-15T12:26:37.444Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}