{"record":{"id":"99357956ee66a826","repo":"charmbracelet/crush","slug":"failed-to-remove-config-field-status-code-d","errorCode":null,"errorMessage":"failed to remove config field: status code %d","messagePattern":"failed to remove config field: status code (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/client/config.go","lineNumber":42,"sourceCode":"\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {\n\t\treturn fmt.Errorf(\"failed to set config field: status code %d\", rsp.StatusCode)\n\t}\n\treturn nil\n}\n\n// RemoveConfigField removes a config key on the server.\nfunc (c *Client) RemoveConfigField(ctx context.Context, id string, scope config.Scope, key string) error {\n\trsp, err := c.post(ctx, fmt.Sprintf(\"/workspaces/%s/config/remove\", id), nil, jsonBody(struct {\n\t\tScope config.Scope `json:\"scope\"`\n\t\tKey   string       `json:\"key\"`\n\t}{Scope: scope, Key: key}), http.Header{\"Content-Type\": []string{\"application/json\"}})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to remove config field: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {\n\t\treturn fmt.Errorf(\"failed to remove config field: status code %d\", rsp.StatusCode)\n\t}\n\treturn nil\n}\n\n// UpdatePreferredModel updates the preferred model on the server.\nfunc (c *Client) UpdatePreferredModel(ctx context.Context, id string, scope config.Scope, modelType config.SelectedModelType, model config.SelectedModel) error {\n\trsp, err := c.post(ctx, fmt.Sprintf(\"/workspaces/%s/config/model\", id), nil, jsonBody(struct {\n\t\tScope     config.Scope             `json:\"scope\"`\n\t\tModelType config.SelectedModelType `json:\"model_type\"`\n\t\tModel     config.SelectedModel     `json:\"model\"`\n\t}{Scope: scope, ModelType: modelType, Model: model}), http.Header{\"Content-Type\": []string{\"application/json\"}})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to update preferred model: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {\n\t\treturn fmt.Errorf(\"failed to update preferred model: status code %d\", rsp.StatusCode)\n\t}","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/client/config.go#L24-L60","documentation":"RemoveConfigField's server-rejection path: the server answered with a non-200 status. No sentinel wrapping is applied; the status code is embedded in the message.","triggerScenarios":"POST /workspaces/{id}/config/remove returns non-200, e.g. 404 unknown workspace or 400 malformed key.","commonSituations":"Logging out of Hyper/Copilot after the workspace was already deleted; removing a key the server never stored.","solutions":["Check the status code in the message to decide whether removal matters","Ignore non-200 during logout cleanup when the key is irrelevant afterward","Ensure the workspace is alive before attempting config mutation"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// Skip the call when the workspace is known to be gone\nif !workspaceExists(id) {\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := c.RemoveConfigField(ctx, id, scope, key); err != nil {\n    if strings.Contains(err.Error(), \"status code 404\") {\n        return nil // already gone\n    }\n    return err\n}","preventionTips":["Treat 404 during cleanup as success","Don't remove keys that were never set","Keep logout paths tolerant of non-200 responses"],"tags":["http","config","bad-request"],"backgroundTag":"http-non-200-response","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}