{"record":{"id":"7c2cf13881efd3fa","repo":"charmbracelet/crush","slug":"failed-to-set-compact-mode-status-code-d","errorCode":null,"errorMessage":"failed to set compact mode: status code %d","messagePattern":"failed to set compact mode: status code (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/client/config.go","lineNumber":75,"sourceCode":"\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}\n\treturn nil\n}\n\n// SetCompactMode sets compact mode on the server.\nfunc (c *Client) SetCompactMode(ctx context.Context, id string, scope config.Scope, enabled bool) error {\n\trsp, err := c.post(ctx, fmt.Sprintf(\"/workspaces/%s/config/compact\", id), nil, jsonBody(struct {\n\t\tScope   config.Scope `json:\"scope\"`\n\t\tEnabled bool         `json:\"enabled\"`\n\t}{Scope: scope, Enabled: enabled}), http.Header{\"Content-Type\": []string{\"application/json\"}})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to set compact mode: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {\n\t\treturn fmt.Errorf(\"failed to set compact mode: status code %d\", rsp.StatusCode)\n\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 {","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/client/config.go#L57-L93","documentation":"SetCompactMode posts the compact-mode toggle to the server and expects HTTP 200. When the request completes but the server responds with any other status code, the client wraps that status in this error. It means the server explicitly rejected the compact-mode change.","triggerScenarios":"Calling SetCompactMode when the server returns a non-200 response, e.g. 404 because the workspace id does not exist, 401/403 for bad credentials, or 500 for a server-side failure.","commonSituations":"Expired or missing auth token, wrong workspace id passed to SetCompactMode, server version that does not implement the compact-mode endpoint (404), or server error while persisting config.","solutions":["Log or inspect the status code embedded in the error to identify the cause","Verify the workspace id passed to SetCompactMode is correct and exists","Check that credentials are valid and not expired (401/403) and re-authenticate","Confirm the server version supports the /config/compact endpoint"],"exampleFix":"// before\nif err := client.SetCompactMode(ctx, wsID, scope, true); err != nil {\n    return err\n}\n// after\nif err := client.SetCompactMode(ctx, wsID, scope, true); err != nil {\n    var statusErr *fmt.StatusError // or inspect err string for \"status code\"\n    if errors.As(err, &statusErr) && statusErr.Code == 401 {\n        if rerr := refreshAuth(ctx); rerr != nil {\n            return rerr\n        }\n        return client.SetCompactMode(ctx, wsID, scope, true)\n    }\n    return err\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := c.SetCompactMode(ctx, wsID, scope, enabled); err != nil {\n    if strings.Contains(err.Error(), \"status code 4\") {\n        // client-side problem: check auth and workspace id\n    }\n    return fmt.Errorf(\"compact mode: %w\", err)\n}","preventionTips":["Validate the workspace id exists before calling config-mutating endpoints","Refresh auth tokens before long-running sessions","Log the status code embedded in the error for diagnostics"],"tags":["http","client","config"],"backgroundTag":"http-non-200-response","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}