{"record":{"id":"aea2a7f1abbe46f8","repo":"charmbracelet/crush","slug":"failed-to-marshal-oauth-token-w","errorCode":null,"errorMessage":"failed to marshal oauth token: %w","messagePattern":"failed to marshal oauth token: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/client/config.go","lineNumber":104,"sourceCode":"\t\tkind proto.APIKeyKind\n\t\traw  json.RawMessage\n\t)\n\tswitch v := apiKey.(type) {\n\tcase string:\n\t\tkind = proto.APIKeyKindString\n\t\tb, err := json.Marshal(v)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to marshal api key string: %w\", err)\n\t\t}\n\t\traw = b\n\tcase *oauth.Token:\n\t\tif v == nil {\n\t\t\treturn fmt.Errorf(\"oauth token is nil\")\n\t\t}\n\t\tkind = proto.APIKeyKindOAuth\n\t\tb, err := json.Marshal(v)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to marshal oauth token: %w\", err)\n\t\t}\n\t\traw = b\n\tdefault:\n\t\treturn fmt.Errorf(\"unsupported api key type %T\", apiKey)\n\t}\n\n\trsp, err := c.post(ctx, fmt.Sprintf(\"/workspaces/%s/config/provider-key\", id), nil, jsonBody(proto.ConfigProviderKeyRequest{\n\t\tScope:      scope,\n\t\tProviderID: providerID,\n\t\tKind:       kind,\n\t\tAPIKey:     raw,\n\t}), http.Header{\"Content-Type\": []string{\"application/json\"}})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to set provider API key: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {\n\t\treturn fmt.Errorf(\"failed to set provider API key: status code %d\", rsp.StatusCode)","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/client/config.go#L86-L122","documentation":"SetProviderAPIKey marshals the *oauth.Token to JSON for the request body. This error wraps a json.Marshal failure on the token — typically caused by a field on the token that cannot be serialized (channels, funcs, or a custom MarshalJSON that errors).","triggerScenarios":"Calling SetProviderAPIKey with an *oauth.Token whose MarshalJSON (or an unexported field with a custom marshaler) returns an error.","commonSituations":"A custom or third-party oauth.Token type with unsupported field types, or a corrupted/populated-with-functions token struct.","solutions":["Inspect the wrapped %w error to find the offending field","Ensure the token struct contains only JSON-serializable fields","Remove or fix any custom MarshalJSON implementation on the token type"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if _, err := json.Marshal(tok); err != nil {\n    return fmt.Errorf(\"oauth token not serializable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := c.SetProviderAPIKey(ctx, wsID, scope, pid, tok); err != nil {\n    if strings.Contains(err.Error(), \"marshal oauth token\") {\n        return fmt.Errorf(\"token contains unsupported fields: %w\", err)\n    }\n    return err\n}","preventionTips":["Use the standard oauth.Token type from the library, not custom structs","Keep token structs free of channels, funcs, and custom failing marshalers"],"tags":["json","oauth","marshal"],"backgroundTag":"json-marshal-failed","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}