{"record":{"id":"a44ec339d113627f","repo":"router-for-me/CLIProxyAPI","slug":"invalid-auth-file-w-a44ec3","errorCode":null,"errorMessage":"invalid auth file: %w","messagePattern":"invalid auth file: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/pluginhost/auth_callbacks.go","lineNumber":318,"sourceCode":"\t\treturn \"\", errUpsert\n\t}\n\treturn dst, nil\n}\n\nfunc (h *Host) buildAuthFromFileData(path string, data []byte) (*coreauth.Auth, error) {\n\tif strings.TrimSpace(path) == \"\" {\n\t\treturn nil, fmt.Errorf(\"auth path is empty\")\n\t}\n\tif data == nil {\n\t\tvar errRead error\n\t\tdata, errRead = os.ReadFile(path)\n\t\tif errRead != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to read auth file: %w\", errRead)\n\t\t}\n\t}\n\tmetadata := make(map[string]any)\n\tif errUnmarshal := json.Unmarshal(data, &metadata); errUnmarshal != nil {\n\t\treturn nil, fmt.Errorf(\"invalid auth file: %w\", errUnmarshal)\n\t}\n\tprovider, _ := metadata[\"type\"].(string)\n\tif strings.TrimSpace(provider) == \"\" {\n\t\tprovider = \"unknown\"\n\t}\n\tlabel := provider\n\tif email, ok := metadata[\"email\"].(string); ok && strings.TrimSpace(email) != \"\" {\n\t\tlabel = strings.TrimSpace(email)\n\t}\n\tauthID := h.authIDForPath(path)\n\tif authID == \"\" {\n\t\tauthID = path\n\t}\n\tauth := &coreauth.Auth{\n\t\tID:       authID,\n\t\tProvider: provider,\n\t\tFileName: filepath.Base(path),\n\t\tLabel:    label,","sourceCodeStart":300,"sourceCodeEnd":336,"githubUrl":"https://github.com/router-for-me/CLIProxyAPI/blob/78f0c4079e3e6273d65d03b5549cffc898703264/internal/pluginhost/auth_callbacks.go#L300-L336","documentation":"Wrapped error from Host.buildAuthFromFileData when json.Unmarshal of the (read or provided) bytes into map[string]any fails. The builder requires a JSON object as the auth metadata source; malformed input aborts record construction before the auth is created or upserted.","triggerScenarios":"Save flow whose data bytes are invalid JSON (should normally be pre-caught by validateHostAuthSaveRequest), or a direct buildAuthFromFileData call with corrupt on-disk content.","commonSituations":"Bypassing the validating save path and calling build directly; file corrupted on disk between validation and build; test fixtures with invalid JSON.","solutions":["Route writes through the validated save request path so JSON is checked first","Validate with json.Valid(data) before calling buildAuthFromFileData","Repair or regenerate the corrupt source file"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if !json.Valid(data) {\n    return fmt.Errorf(\"auth data for %s is not valid JSON\", path)\n}","typeGuard":null,"tryCatchPattern":"var synErr *json.SyntaxError\nif errors.As(err, &synErr) {\n    // locate corruption via offset and regenerate the file\n}","preventionTips":["Route all writes through the validating save path","json.Valid-check fixtures and files before direct build calls"],"tags":["go","pluginhost","auth","json","corruption"],"backgroundTag":null,"analyzedSha":"78f0c4079e3e6273d65d03b5549cffc898703264","analyzedAt":"2026-08-15T12:26:37.444Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}