charmbracelet/crush · error
failed to set config field: status code
Error message
failed to set config field: status code %d
What it means
SetConfigField's server-rejection path: the request reached the server but the status code was not 200. Unlike other client methods this does not use checkStatus, so no sentinel (e.g. ErrNotFound) is applied.
Solutions
- Log the returned status code and inspect server logs for the rejection reason
- Validate the key/value against supported config fields before calling
- Confirm the workspace id exists before mutating its config
Defensive patterns
Strategy: validation
Validate before calling
// Validate inputs before calling
if id == "" {
return fmt.Errorf("workspace id is required")
}
if key == "" {
return fmt.Errorf("config key is required")
} Try / catch
if err := c.SetConfigField(ctx, id, scope, key, value); err != nil {
var statusErr interface{ Error() string }
_ = statusErr
// message embeds the status code; log it and inspect server logs
return fmt.Errorf("config set rejected: %w", err)
} Prevention
- Only set keys the server recognizes
- Verify the workspace exists before mutation
- Match client/server versions to avoid unknown-field rejections
When it happens
Trigger: POST /workspaces/{id}/config/set returns any status other than 200 (e.g. 400 bad key/value, 404 unknown workspace, 500 server error).
Common situations: Setting a config key the server does not recognize; workspace already torn down; server-side validation rejecting the value type.
Related errors
- failed to remove config field: status code
- could not create request
- failed to create request for provider
- failed to get config
- failed to remove config field
AI-assisted analysis of charmbracelet/crush@7944b8e522 (2026-08-29).
Data as JSON: /api/errors/fd1351913417495d.
Report an issue: GitHub.
Appendix: source
Thrown at internal/client/config.go:26
"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()
if rsp.StatusCode != http.StatusOK {
return fmt.Errorf("failed to remove config field: status code %d", rsp.StatusCode)
}
return nilView on GitHub (pinned to 7944b8e522)