charmbracelet/crush · error
failed to import copilot: %w
Error message
failed to import copilot: %w
What it means
ImportCopilot asks the server to import a GitHub Copilot token via POST /workspaces/{id}/config/import-copilot. If the HTTP request fails at the transport level, the error is wrapped with this message.
Source
Thrown at internal/client/config.go:132
Kind: kind,
APIKey: raw,
}), http.Header{"Content-Type": []string{"application/json"}})
if err != nil {
return fmt.Errorf("failed to set provider API key: %w", err)
}
defer rsp.Body.Close()
if rsp.StatusCode != http.StatusOK {
return fmt.Errorf("failed to set provider API key: status code %d", rsp.StatusCode)
}
return nil
}
// ImportCopilot attempts to import a GitHub Copilot token on the
// server.
func (c *Client) ImportCopilot(ctx context.Context, id string) (*oauth.Token, bool, error) {
rsp, err := c.post(ctx, fmt.Sprintf("/workspaces/%s/config/import-copilot", id), nil, nil, nil)
if err != nil {
return nil, false, fmt.Errorf("failed to import copilot: %w", err)
}
defer rsp.Body.Close()
if rsp.StatusCode != http.StatusOK {
return nil, false, fmt.Errorf("failed to import copilot: status code %d", rsp.StatusCode)
}
var result struct {
Token *oauth.Token `json:"token"`
Success bool `json:"success"`
}
if err := json.NewDecoder(rsp.Body).Decode(&result); err != nil {
return nil, false, fmt.Errorf("failed to decode import copilot response: %w", err)
}
return result.Token, result.Success, nil
}
// RefreshOAuthToken refreshes an OAuth token for a provider on the
// server.
func (c *Client) RefreshOAuthToken(ctx context.Context, id string, scope config.Scope, providerID string) error {View on GitHub (pinned to 7944b8e522)
Solutions
- Confirm the server is running and reachable
- Check the client base URL/port configuration
- Inspect the wrapped %w error for the transport-level cause
- Retry with network access restored or a longer timeout
Defensive patterns
Strategy: retry
Validate before calling
conn, err := net.DialTimeout("tcp", serverHost, 2*time.Second)
if err != nil {
return fmt.Errorf("server not reachable: %w", err)
}
conn.Close() Try / catch
tok, ok, err := c.ImportCopilot(ctx, wsID)
for attempt := 0; attempt < 3 && isTransient(err); attempt++ {
time.Sleep(backoff(attempt))
tok, ok, err = c.ImportCopilot(ctx, wsID)
} Prevention
- Check network/VPN connectivity before running import flows
- Always pass a cancellable context with a timeout
- Surface transport errors to users with actionable messages
When it happens
Trigger: Calling ImportCopilot when the server is unreachable: connection refused, TLS/DNS failure, or context cancellation/deadline exceeded.
Common situations: Server not started, misconfigured base URL, machine has no network access, or user cancels the context during import.
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
- failed to download from URL: %w
- failed to create request: %w
- failed to fetch URL: %w
- failed to fetch URL: %w
- failed to create request: %w
AI-assisted analysis of charmbracelet/crush@7944b8e522 (2026-08-29).
Data as JSON: /api/errors/2e01d8439e2f23f9.
Report an issue: GitHub.