charmbracelet/crush · error
failed to set config field: %w
Error message
failed to set config field: %w
What it means
SetConfigField wraps a transport-level failure of the POST to /workspaces/{id}/config/set. The config change never reached the server.
Source
Thrown at internal/client/config.go:22
"context"
"encoding/json"
"fmt"
"net/http"
"github.com/charmbracelet/crush/internal/config"
"github.com/charmbracelet/crush/internal/oauth"
"github.com/charmbracelet/crush/internal/proto"
)
// SetConfigField sets a config key/value pair on the server.
func (c *Client) SetConfigField(ctx context.Context, id string, scope config.Scope, key string, value any) error {
rsp, err := c.post(ctx, fmt.Sprintf("/workspaces/%s/config/set", id), nil, jsonBody(struct {
Scope config.Scope `json:"scope"`
Key string `json:"key"`
Value any `json:"value"`
}{Scope: scope, Key: key, Value: value}), http.Header{"Content-Type": []string{"application/json"}})
if err != nil {
return fmt.Errorf("failed to set config field: %w", err)
}
defer rsp.Body.Close()
if rsp.StatusCode != http.StatusOK {
return fmt.Errorf("failed to set config field: status code %d", rsp.StatusCode)
}
return nil
}
// RemoveConfigField removes a config key on the server.
func (c *Client) RemoveConfigField(ctx context.Context, id string, scope config.Scope, key string) error {
rsp, err := c.post(ctx, fmt.Sprintf("/workspaces/%s/config/remove", id), nil, jsonBody(struct {
Scope config.Scope `json:"scope"`
Key string `json:"key"`
}{Scope: scope, Key: key}), http.Header{"Content-Type": []string{"application/json"}})
if err != nil {
return fmt.Errorf("failed to remove config field: %w", err)
}
defer rsp.Body.Close()View on GitHub (pinned to 7944b8e522)
Solutions
- Check the wrapped error for connectivity issues and verify the server is reachable
- Verify the workspace id and that the context has adequate deadline
- Retry the call once the connection is restored
Defensive patterns
Strategy: retry
Validate before calling
// Ensure the context is alive and server reachable before the call
if err := ctx.Err(); err != nil {
return err
}
req, _ := http.NewRequestWithContext(ctx, http.MethodGet, healthURL, nil)
if _, err := http.DefaultClient.Do(req); err != nil {
return fmt.Errorf("server unreachable: %w", err)
} Try / catch
if err := c.SetConfigField(ctx, id, scope, key, value); err != nil {
if errors.Is(err, context.DeadlineExceeded) || isConnRefused(err) {
// retry with backoff
}
return err
} Prevention
- Pass contexts with adequate deadlines
- Confirm server connectivity before config mutations
- Retry idempotent config sets on transport failure
When it happens
Trigger: c.post returns an error: connection refused, context canceled/expired, or request encoding failure when setting a config field.
Common situations: Server not running or socket path wrong; context deadline exceeded during a slow request; workspace id invalid causing an earlier failure.
Understand the failure class
Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.
Related errors
- failed to remove config field: %w
- failed to set compact mode: %w
- failed to get config: %w
- failed to set large model: %w
- failed to set small model: %w
AI-assisted analysis of charmbracelet/crush@7944b8e522 (2026-08-29).
Data as JSON: /api/errors/dd6ce590b9ee2915.
Report an issue: GitHub.