{"record":{"id":"45c0eefe7994e427","repo":"router-for-me/CLIProxyAPI","slug":"invalid-auth-json-w","errorCode":null,"errorMessage":"invalid auth json: %w","messagePattern":"invalid auth json: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/pluginhost/auth_callbacks.go","lineNumber":276,"sourceCode":"\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 {\n\t\treturn \"\", nil, fmt.Errorf(\"invalid auth json: %w\", errUnmarshal)\n\t}\n\treturn filepath.Base(name), rawJSON, nil\n}\n\nfunc (h *Host) saveAuthFile(ctx context.Context, name string, data []byte) (string, error) {\n\tauthDir := h.resolvedAuthDir()\n\tif authDir == \"\" {\n\t\treturn \"\", fmt.Errorf(\"auth directory is unavailable\")\n\t}\n\tdst := filepath.Join(authDir, filepath.Base(name))\n\tif !filepath.IsAbs(dst) {\n\t\tif abs, errAbs := filepath.Abs(dst); errAbs == nil {\n\t\t\tdst = abs\n\t\t}\n\t}\n\tauth, errBuild := h.buildAuthFromFileData(dst, data)\n\tif errBuild != nil {\n\t\treturn \"\", errBuild","sourceCodeStart":258,"sourceCodeEnd":294,"githubUrl":"https://github.com/router-for-me/CLIProxyAPI/blob/78f0c4079e3e6273d65d03b5549cffc898703264/internal/pluginhost/auth_callbacks.go#L258-L294","documentation":"Wrapped error from validateHostAuthSaveRequest when json.Unmarshal of the submitted JSON into map[string]any fails. The payload is non-empty but syntactically invalid JSON, so it cannot be persisted as an auth file.","triggerScenarios":"Plugin passes a hand-built string, YAML, form-encoded data, or a truncated buffer as req.JSON; double-encoding (a quoted JSON string containing JSON) that does not decode to an object.","commonSituations":"String concatenation instead of json.Marshal in the plugin; a proxy or transport layer mangling the payload; copy from documentation with smart quotes.","solutions":["Build the payload with json.Marshal of a struct or map instead of string building","Check the wrapped error's offset (SyntaxError.Offset) to find the invalid character","Validate locally with json.Valid([]byte(req.JSON)) before invoking save"],"exampleFix":"// before\nreq.JSON := fmt.Sprintf(\"{provider: %s}\", p) // unquoted key, invalid\n\n// after\nb, _ := json.Marshal(map[string]any{\"type\": p, \"email\": e})\nreq.JSON = string(b)","handlingStrategy":"validation","validationCode":"if !json.Valid([]byte(req.JSON)) {\n    return fmt.Errorf(\"payload is not valid JSON\")\n}","typeGuard":null,"tryCatchPattern":"var synErr *json.SyntaxError\nif errors.As(err, &synErr) {\n    // report synErr.Offset to the payload producer (plugin)\n}","preventionTips":["Build payloads with json.Marshal, never string concatenation","Round-trip check: unmarshal what you marshaled before sending"],"tags":["go","pluginhost","auth","json","validation"],"backgroundTag":null,"analyzedSha":"78f0c4079e3e6273d65d03b5549cffc898703264","analyzedAt":"2026-08-15T12:26:37.444Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}