{"record":{"id":"e8c108a5a9b0955f","repo":"charmbracelet/crush","slug":"failed-to-mark-project-initialized-status-code-d","errorCode":null,"errorMessage":"failed to mark project initialized: status code %d","messagePattern":"failed to mark project initialized: status code (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/client/config.go","lineNumber":194,"sourceCode":"\tvar result struct {\n\t\tNeedsInit bool `json:\"needs_init\"`\n\t}\n\tif err := json.NewDecoder(rsp.Body).Decode(&result); err != nil {\n\t\treturn false, fmt.Errorf(\"failed to decode project init response: %w\", err)\n\t}\n\treturn result.NeedsInit, nil\n}\n\n// MarkProjectInitialized marks the project as initialized on the\n// server.\nfunc (c *Client) MarkProjectInitialized(ctx context.Context, id string) error {\n\trsp, err := c.post(ctx, fmt.Sprintf(\"/workspaces/%s/project/init\", id), nil, nil, nil)\n\tif err != nil {\n\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}","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/client/config.go#L176-L212","documentation":"MarkProjectInitialized requires HTTP 200 from POST /workspaces/{id}/project/init; any other status raises this error. The server processed the request but refused to mark the project as initialized.","triggerScenarios":"Calling MarkProjectInitialized and receiving non-200: 401/403 for insufficient workspace permissions, 404 for an unknown workspace id, 409 if the server considers state inconsistent, or 5xx on a persistence failure.","commonSituations":"Caller authenticated as a user without write access to the workspace; workspace deleted concurrently; server database write failure during initialization; stale credentials after re-login on the server side.","solutions":["Map the status code: 401/403 → re-authenticate with adequate permissions, 404 → verify the workspace id","Retry only on 429/5xx; client errors need corrected credentials or ids","Check server logs/database health for persistent 5xx","Confirm the workspace still exists before re-marking"],"exampleFix":"// before\nif err := client.MarkProjectInitialized(ctx, id); err != nil {\n    return err\n}\n// after\nif err := client.MarkProjectInitialized(ctx, id); err != nil {\n    if strings.Contains(err.Error(), \"status code 403\") {\n        return ErrInsufficientPermissions\n    }\n    return err\n}","handlingStrategy":"try-catch","validationCode":"// Ensure the workspace exists and caller has write access before marking\nws, err := client.GetWorkspace(ctx, id)\nif err != nil {\n    return err\n}\nif !ws.Permissions.Write {\n    return fmt.Errorf(\"no write access to workspace %s\", 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":"if err := c.MarkProjectInitialized(ctx, id); err != nil {\n    if isStatusError(err, 401) || isStatusError(err, 403) {\n        return ErrInsufficientPermissions\n    }\n    if isStatusError(err, 404) {\n        return ErrWorkspaceNotFound\n    }\n    return err\n}","preventionTips":["Verify workspace membership/permissions before initialization flows","Retry only 429/5xx; handle 4xx by fixing credentials or ids","Re-fetch the workspace if initialization may have raced with deletion","Check server persistence health for recurring 5xx on this endpoint"],"tags":["http-client","http-status","permissions"],"backgroundTag":"unexpected-http-status","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}