{"record":{"id":"3780140746eb5ee7","repo":"router-for-me/CLIProxyAPI","slug":"failed-to-marshal-request-body-w","errorCode":null,"errorMessage":"failed to marshal request body: %w","messagePattern":"failed to marshal request body: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/auth/claude/anthropic_auth.go","lineNumber":395,"sourceCode":"\t// order Claude Code 2.1.220 emits on the wire; a map would be re-sorted\n\t// alphabetically by encoding/json and change the serialized body bytes.\n\treqBody := authorizationCodeExchangeRequest{\n\t\tGrantType:    \"authorization_code\",\n\t\tCode:         newCode,\n\t\tRedirectURI:  RedirectURI,\n\t\tClientID:     ClientID,\n\t\tCodeVerifier: pkceCodes.CodeVerifier,\n\t\tState:        state,\n\t}\n\n\t// A state fragment appended to the callback code takes precedence.\n\tif newState != \"\" {\n\t\treqBody.State = newState\n\t}\n\n\tjsonBody, err := json.Marshal(reqBody)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to marshal request body: %w\", err)\n\t}\n\n\t// log.Debugf(\"Token exchange request: %s\", string(jsonBody))\n\n\treq, err := http.NewRequestWithContext(ctx, \"POST\", TokenURL, strings.NewReader(string(jsonBody)))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create token request: %w\", err)\n\t}\n\tapplyClaudeOAuthAxiosHeaders(req)\n\n\tresp, err := o.httpClient.Do(req)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"token exchange request failed: %w\", err)\n\t}\n\tdefer func() {\n\t\tif errClose := resp.Body.Close(); errClose != nil {\n\t\t\tlog.Errorf(\"failed to close response body: %v\", errClose)\n\t\t}","sourceCodeStart":377,"sourceCodeEnd":413,"githubUrl":"https://github.com/router-for-me/CLIProxyAPI/blob/78f0c4079e3e6273d65d03b5549cffc898703264/internal/auth/claude/anthropic_auth.go#L377-L413","documentation":"Error \"failed to marshal request body: %w\" thrown in router-for-me/CLIProxyAPI.","triggerScenarios":"Thrown at internal/auth/claude/anthropic_auth.go:395 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the wrapped marshal error for unsupported values in the request body struct.","Verify the token request fields are populated with serializable values."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"78f0c4079e3e6273d65d03b5549cffc898703264","analyzedAt":"2026-08-15T12:26:37.444Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}