{"record":{"id":"f6ad2c8879ab2b0a","repo":"charmbracelet/crush","slug":"failed-to-get-sessions-status-code-d","errorCode":null,"errorMessage":"failed to get sessions: status code %d","messagePattern":"failed to get sessions: status code (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/client/proto.go","lineNumber":666,"sourceCode":"\tif rsp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"failed to create session: status code %d\", rsp.StatusCode)\n\t}\n\tvar sess proto.Session\n\tif err := json.NewDecoder(rsp.Body).Decode(&sess); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to decode session: %w\", err)\n\t}\n\treturn &sess, nil\n}\n\n// ListSessions lists all sessions in a workspace as proto types.\nfunc (c *Client) ListSessions(ctx context.Context, id string) ([]proto.Session, error) {\n\trsp, err := c.get(ctx, fmt.Sprintf(\"/workspaces/%s/sessions\", id), nil, nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get sessions: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"failed to get sessions: status code %d\", rsp.StatusCode)\n\t}\n\tvar sessions []proto.Session\n\tif err := json.NewDecoder(rsp.Body).Decode(&sessions); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to decode sessions: %w\", err)\n\t}\n\treturn sessions, nil\n}\n\n// GrantPermission grants a permission on a workspace. The returned\n// bool reports whether this call resolved the pending request (true)\n// or found it already resolved by a previous caller (false). A false\n// value is not an error — it just means another subscriber resolved\n// the same request first.\nfunc (c *Client) GrantPermission(ctx context.Context, id string, req proto.PermissionGrant) (bool, error) {\n\trsp, err := c.post(ctx, fmt.Sprintf(\"/workspaces/%s/permissions/grant\", id), nil, jsonBody(req), http.Header{\"Content-Type\": []string{\"application/json\"}})\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"failed to grant permission: %w\", err)\n\t}","sourceCodeStart":648,"sourceCodeEnd":684,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/client/proto.go#L648-L684","documentation":"ListSessions reached the server but got a non-200 status for GET /workspaces/{id}/sessions. The status code is included in the error. Typical causes: 404 (workspace not found), 401/403 (auth/permissions), 5xx (server error).","triggerScenarios":"Workspace ID does not exist (404); credentials invalid or expired (401/403); server error while enumerating sessions (500); rate limiting (429).","commonSituations":"Typo in workspace ID; token expired; insufficient permissions on the workspace; server-side outage.","solutions":["Branch on the status code from the error message.","Verify the workspace ID exists.","Refresh authentication credentials.","Check permissions for the workspace.","Retry with backoff on 429/5xx."],"exampleFix":"// before\nsessions, err := client.ListSessions(ctx, wsID)\nif err != nil { return err }\n// after\nsessions, err := client.ListSessions(ctx, wsID)\nif err != nil {\n    if strings.Contains(err.Error(), \"status code 404\") {\n        return fmt.Errorf(\"workspace %q not found\", wsID)\n    }\n    return err\n}","handlingStrategy":"try-catch","validationCode":"// Confirm the workspace exists before listing\n_, err := client.GetWorkspace(ctx, wsID)\nif err != nil {\n    return fmt.Errorf(\"workspace %q not accessible: %w\", wsID, err)\n}","typeGuard":"func isListStatusError(err error, code int) bool {\n    return err != nil && strings.Contains(err.Error(), fmt.Sprintf(\"failed to get sessions: status code %d\", code))\n}","tryCatchPattern":"sessions, err := client.ListSessions(ctx, wsID)\nif err != nil {\n    switch {\n    case isListStatusError(err, 404):\n        return fmt.Errorf(\"workspace %q not found\", wsID)\n    case isListStatusError(err, 401), isListStatusError(err, 403):\n        return fmt.Errorf(\"auth required: %w\", err)\n    }\n    return err\n}","preventionTips":["Validate workspace IDs up front.","Refresh credentials before expiry.","Check permissions for the workspace.","Retry only 429/5xx responses."],"tags":["http","status-code","client"],"backgroundTag":"http-non-200-response","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}