{"record":{"id":"378a69f307c4bca7","repo":"router-for-me/CLIProxyAPI","slug":"invalid-auth-file-for-auth-index-s-w","errorCode":null,"errorMessage":"invalid auth file for auth_index %s: %w","messagePattern":"invalid auth file for auth_index (.+?): %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/pluginhost/auth_callbacks.go","lineNumber":257,"sourceCode":"\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 {\n\t\treturn \"\", nil, fmt.Errorf(\"json is required\")\n\t}\n\tvar metadata map[string]any\n\tif errUnmarshal := json.Unmarshal(rawJSON, &metadata); errUnmarshal != nil {","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/router-for-me/CLIProxyAPI/blob/78f0c4079e3e6273d65d03b5549cffc898703264/internal/pluginhost/auth_callbacks.go#L239-L275","documentation":"Wrapped error from Host.authPhysicalJSONByIndex when json.Unmarshal of the auth file into map[string]any fails. The file exists and is non-empty but is not valid JSON, so it cannot be interpreted as an auth record.","triggerScenarios":"Auth file containing JSON5/YAML/HTML (e.g. an error page saved by a fetch), truncated JSON, BOM-prefixed or doubly-encoded content; a log line accidentally written into the auth file.","commonSituations":"Manual editing of auths/*.json introducing a syntax error; scripts writing pretty-printed or commented JSON; partial writes from non-atomic producers.","solutions":["Validate the file with a JSON linter (jq . auths/file.json) to locate the syntax error","Fix or regenerate the file; re-run the OAuth flow if regeneration is easier","Ensure only the proxy writes auth files, with atomic write-then-rename"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"data, err := os.ReadFile(path)\nif err == nil && !json.Valid(data) {\n    // reject/repair before passing to the host\n}","typeGuard":null,"tryCatchPattern":"var synErr *json.SyntaxError\nif errors.As(err, &synErr) {\n    // use synErr.Offset to locate the malformed JSON in the auth file\n}","preventionTips":["Never hand-edit auth files without a JSON validator","jq-validate files after scripted modifications"],"tags":["go","pluginhost","auth","json","corruption"],"backgroundTag":null,"analyzedSha":"78f0c4079e3e6273d65d03b5549cffc898703264","analyzedAt":"2026-08-15T12:26:37.444Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}