charmbracelet/crush · error

failed to mark project initialized: status code %d

Error message

failed to mark project initialized: status code %d

What it means

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.

Source

Thrown at internal/client/config.go:194

	var result struct {
		NeedsInit bool `json:"needs_init"`
	}
	if err := json.NewDecoder(rsp.Body).Decode(&result); err != nil {
		return false, fmt.Errorf("failed to decode project init response: %w", err)
	}
	return result.NeedsInit, nil
}

// MarkProjectInitialized marks the project as initialized on the
// server.
func (c *Client) MarkProjectInitialized(ctx context.Context, id string) error {
	rsp, err := c.post(ctx, fmt.Sprintf("/workspaces/%s/project/init", id), nil, nil, nil)
	if err != nil {
		return fmt.Errorf("failed to mark project initialized: %w", err)
	}
	defer rsp.Body.Close()
	if rsp.StatusCode != http.StatusOK {
		return fmt.Errorf("failed to mark project initialized: status code %d", rsp.StatusCode)
	}
	return nil
}

// GetInitializePrompt retrieves the initialization prompt from the
// server.
func (c *Client) GetInitializePrompt(ctx context.Context, id string) (string, error) {
	rsp, err := c.get(ctx, fmt.Sprintf("/workspaces/%s/project/init-prompt", id), nil, nil)
	if err != nil {
		return "", fmt.Errorf("failed to get init prompt: %w", err)
	}
	defer rsp.Body.Close()
	if rsp.StatusCode != http.StatusOK {
		return "", fmt.Errorf("failed to get init prompt: status code %d", rsp.StatusCode)
	}
	var result struct {
		Prompt string `json:"prompt"`
	}

View on GitHub (pinned to 7944b8e522)

Solutions

  1. Map the status code: 401/403 → re-authenticate with adequate permissions, 404 → verify the workspace id
  2. Retry only on 429/5xx; client errors need corrected credentials or ids
  3. Check server logs/database health for persistent 5xx
  4. Confirm the workspace still exists before re-marking

Example fix

// before
if err := client.MarkProjectInitialized(ctx, id); err != nil {
    return err
}
// after
if err := client.MarkProjectInitialized(ctx, id); err != nil {
    if strings.Contains(err.Error(), "status code 403") {
        return ErrInsufficientPermissions
    }
    return err
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Ensure the workspace exists and caller has write access before marking
ws, err := client.GetWorkspace(ctx, id)
if err != nil {
    return err
}
if !ws.Permissions.Write {
    return fmt.Errorf("no write access to workspace %s", id)
}

Type guard

func isStatusError(err error, code int) bool {
    return err != nil && strings.Contains(err.Error(), fmt.Sprintf("status code %d", code))
}

Try / catch

if err := c.MarkProjectInitialized(ctx, id); err != nil {
    if isStatusError(err, 401) || isStatusError(err, 403) {
        return ErrInsufficientPermissions
    }
    if isStatusError(err, 404) {
        return ErrWorkspaceNotFound
    }
    return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of charmbracelet/crush@7944b8e522 (2026-08-29). Data as JSON: /api/errors/e8c108a5a9b0955f. Report an issue: GitHub.