charmbracelet/crush · error

failed to check project init: %w

Error message

failed to check project init: %w

What it means

ProjectNeedsInitialization performs GET /workspaces/{id}/project/needs-init and wraps any transport-level failure of that request with this error. The boolean result could not be obtained because the request itself failed before a response arrived.

Source

Thrown at internal/client/config.go:170

		Scope      config.Scope `json:"scope"`
		ProviderID string       `json:"provider_id"`
	}{Scope: scope, ProviderID: providerID}), http.Header{"Content-Type": []string{"application/json"}})
	if err != nil {
		return fmt.Errorf("failed to refresh OAuth token: %w", err)
	}
	defer rsp.Body.Close()
	if rsp.StatusCode != http.StatusOK {
		return fmt.Errorf("failed to refresh OAuth token: status code %d", rsp.StatusCode)
	}
	return nil
}

// ProjectNeedsInitialization checks if the project needs
// initialization.
func (c *Client) ProjectNeedsInitialization(ctx context.Context, id string) (bool, error) {
	rsp, err := c.get(ctx, fmt.Sprintf("/workspaces/%s/project/needs-init", id), nil, nil)
	if err != nil {
		return false, fmt.Errorf("failed to check project init: %w", err)
	}
	defer rsp.Body.Close()
	if rsp.StatusCode != http.StatusOK {
		return false, fmt.Errorf("failed to check project init: status code %d", rsp.StatusCode)
	}
	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)

View on GitHub (pinned to 7944b8e522)

Solutions

  1. Confirm the server is running and the client base URL is correct
  2. Check ctx cancellation/deadline — a cancelled context surfaces as a wrapped request error
  3. Retry on transient network errors before giving up on project initialization
  4. Inspect the wrapped cause with errors.As to classify timeout vs connection refused

Example fix

// before
needsInit, err := client.ProjectNeedsInitialization(ctx, id)
if err != nil {
    return err
}
// after
needsInit, err := client.ProjectNeedsInitialization(ctx, id)
if err != nil {
    if isRetryable(err) {
        needsInit, err = client.ProjectNeedsInitialization(ctx, id)
    }
    if err != nil {
        return fmt.Errorf("bootstrap: %w", err)
    }
}
Defensive patterns

Strategy: retry

Validate before calling

// Check the server is reachable before bootstrap queries
resp, err := http.Get(client.BaseURL() + "/healthz")
if err != nil || resp.StatusCode != http.StatusOK {
    return fmt.Errorf("server not ready")
}
resp.Body.Close()

Type guard

func isTransportError(err error) bool {
    var netErr net.Error
    return errors.As(err, &netErr)
}

Try / catch

needsInit, err := c.ProjectNeedsInitialization(ctx, id)
if err != nil {
    var netErr net.Error
    if errors.As(err, &netErr) {
        return retryWithBackoff(ctx, func() error { _, err = c.ProjectNeedsInitialization(ctx, id); return err })
    }
    return err
}

Prevention

When it happens

Trigger: Calling Client.ProjectNeedsInitialization(ctx, id) when the GET request fails at the transport layer: unreachable server, reset connection, TLS error, or context cancellation.

Common situations: Offline development machine; server not started yet during local setup; wrong base URL or port in client configuration; corporate proxy blocking the call at project bootstrap time.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


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