{"record":{"id":"1d7bdd0e05680d43","repo":"charmbracelet/crush","slug":"failed-to-marshal-api-key-string-w","errorCode":null,"errorMessage":"failed to marshal api key string: %w","messagePattern":"failed to marshal api key string: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/client/config.go","lineNumber":94,"sourceCode":"\t}\n\treturn nil\n}\n\n// SetProviderAPIKey sets a provider API key on the server. The wire\n// format tags the credential with an explicit Kind so the server can\n// decode it back into the right Go type — JSON's `any` loses that\n// information across the socket.\nfunc (c *Client) SetProviderAPIKey(ctx context.Context, id string, scope config.Scope, providerID string, apiKey any) error {\n\tvar (\n\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,","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/client/config.go#L76-L112","documentation":"SetProviderAPIKey marshals a string API key to JSON before sending it. json.Marshal on a plain Go string cannot realistically fail, so this error is defensive; if it ever occurs the JSON encoding layer itself is broken (e.g. corrupted encoding state via custom marshalers).","triggerScenarios":"Calling SetProviderAPIKey with a string apiKey where json.Marshal(v) returns an error — practically never for a plain string.","commonSituations":"Essentially unreachable in normal use; would indicate a corrupted runtime or a custom string type with a failing MarshalJSON method.","solutions":["Inspect the wrapped %w error for details from json.Marshal","If apiKey is a custom string type, check whether it defines a MarshalJSON method that errors","Retry the call; if it persists, report a bug in the client"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if _, err := json.Marshal(apiKey); err != nil {\n    return fmt.Errorf(\"key not serializable: %w\", err)\n}\n// proceed with SetProviderAPIKey","preventionTips":["Pass plain string API keys, not custom wrapper types with marshalers","Treat this error as a bug and report it if it ever occurs"],"tags":["json","marshal","client"],"backgroundTag":"json-marshal-failed","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}