{"record":{"id":"2994522d00ee36eb","repo":"charmbracelet/crush","slug":"failed-to-get-init-prompt-status-code-d","errorCode":null,"errorMessage":"failed to get init prompt: status code %d","messagePattern":"failed to get init prompt: status code (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/client/config.go","lineNumber":208,"sourceCode":"\t\treturn fmt.Errorf(\"failed to mark project initialized: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {\n\t\treturn fmt.Errorf(\"failed to mark project initialized: status code %d\", rsp.StatusCode)\n\t}\n\treturn nil\n}\n\n// GetInitializePrompt retrieves the initialization prompt from the\n// server.\nfunc (c *Client) GetInitializePrompt(ctx context.Context, id string) (string, error) {\n\trsp, err := c.get(ctx, fmt.Sprintf(\"/workspaces/%s/project/init-prompt\", id), nil, nil)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to get init prompt: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {\n\t\treturn \"\", fmt.Errorf(\"failed to get init prompt: status code %d\", rsp.StatusCode)\n\t}\n\tvar result struct {\n\t\tPrompt string `json:\"prompt\"`\n\t}\n\tif err := json.NewDecoder(rsp.Body).Decode(&result); err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to decode init prompt response: %w\", err)\n\t}\n\treturn result.Prompt, nil\n}\n\n// ListSkills retrieves the visible skills for a workspace.\nfunc (c *Client) ListSkills(ctx context.Context, id string) ([]proto.SkillInfo, error) {\n\trsp, err := c.get(ctx, fmt.Sprintf(\"/workspaces/%s/skills\", id), nil, nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to list skills: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/client/config.go#L190-L226","documentation":"GetInitializePrompt requires HTTP 200 from GET /workspaces/{id}/project/init-prompt; any other status produces this error. The server was reached but refused to return the initialization prompt, so callers like InitializePrompt receive a wrapped failure.","triggerScenarios":"Calling GetInitializePrompt (or InitializePrompt) and the server responds non-200: 401/403 for unauthorized workspace access, 404 for a non-existent workspace, or 5xx when the server cannot load its prompt template.","commonSituations":"Querying a workspace before it was fully created; expired auth session during onboarding; server misconfigured without its prompt assets; multi-tenant deployments where the user lacks access to the given workspace id.","solutions":["Read the status code: 401/403 → re-authenticate, 404 → verify the workspace id exists","Ensure the workspace was created and initialized server-side before fetching its prompt","Check server deployment/assets if 5xx persists","Refresh client credentials if auth recently expired"],"exampleFix":"// before\nprompt, err := client.GetInitializePrompt(ctx, id)\nif err != nil {\n    return err\n}\n// after\nprompt, err := client.GetInitializePrompt(ctx, id)\nif err != nil {\n    if strings.Contains(err.Error(), \"status code 404\") {\n        return fmt.Errorf(\"workspace %s not found: %w\", id, err)\n    }\n    return err\n}","handlingStrategy":"try-catch","validationCode":"// Confirm the workspace exists before requesting its init prompt\nws, err := client.GetWorkspace(ctx, id)\nif err != nil {\n    return err\n}\nif ws == nil {\n    return fmt.Errorf(\"workspace %s not found\", id)\n}","typeGuard":"func isStatusError(err error, code int) bool {\n    return err != nil && strings.Contains(err.Error(), fmt.Sprintf(\"status code %d\", code))\n}","tryCatchPattern":"prompt, err := c.GetInitializePrompt(ctx, id)\nif err != nil {\n    if isStatusError(err, 401) || isStatusError(err, 403) {\n        return reauthenticate(ctx)\n    }\n    if isStatusError(err, 404) {\n        return ErrWorkspaceNotFound\n    }\n    return err\n}","preventionTips":["Create/initialize the workspace before fetching its prompt","Refresh credentials before onboarding flows to prevent 401/403","Map status codes to distinct sentinel errors for clean handling","Retry only 429/5xx statuses, never 4xx"],"tags":["http-client","http-status","bootstrap"],"backgroundTag":"unexpected-http-status","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}