{"record":{"id":"2e01d8439e2f23f9","repo":"charmbracelet/crush","slug":"failed-to-import-copilot-w","errorCode":null,"errorMessage":"failed to import copilot: %w","messagePattern":"failed to import copilot: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/client/config.go","lineNumber":132,"sourceCode":"\t\tKind:       kind,\n\t\tAPIKey:     raw,\n\t}), http.Header{\"Content-Type\": []string{\"application/json\"}})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to set provider API key: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {\n\t\treturn fmt.Errorf(\"failed to set provider API key: status code %d\", rsp.StatusCode)\n\t}\n\treturn nil\n}\n\n// ImportCopilot attempts to import a GitHub Copilot token on the\n// server.\nfunc (c *Client) ImportCopilot(ctx context.Context, id string) (*oauth.Token, bool, error) {\n\trsp, err := c.post(ctx, fmt.Sprintf(\"/workspaces/%s/config/import-copilot\", id), nil, nil, nil)\n\tif err != nil {\n\t\treturn nil, false, fmt.Errorf(\"failed to import copilot: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {\n\t\treturn nil, false, fmt.Errorf(\"failed to import copilot: status code %d\", rsp.StatusCode)\n\t}\n\tvar result struct {\n\t\tToken   *oauth.Token `json:\"token\"`\n\t\tSuccess bool         `json:\"success\"`\n\t}\n\tif err := json.NewDecoder(rsp.Body).Decode(&result); err != nil {\n\t\treturn nil, false, fmt.Errorf(\"failed to decode import copilot response: %w\", err)\n\t}\n\treturn result.Token, result.Success, nil\n}\n\n// RefreshOAuthToken refreshes an OAuth token for a provider on the\n// server.\nfunc (c *Client) RefreshOAuthToken(ctx context.Context, id string, scope config.Scope, providerID string) error {","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/client/config.go#L114-L150","documentation":"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.","triggerScenarios":"Calling ImportCopilot when the server is unreachable: connection refused, TLS/DNS failure, or context cancellation/deadline exceeded.","commonSituations":"Server not started, misconfigured base URL, machine has no network access, or user cancels the context during import.","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"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"conn, err := net.DialTimeout(\"tcp\", serverHost, 2*time.Second)\nif err != nil {\n    return fmt.Errorf(\"server not reachable: %w\", err)\n}\nconn.Close()","typeGuard":null,"tryCatchPattern":"tok, ok, err := c.ImportCopilot(ctx, wsID)\nfor attempt := 0; attempt < 3 && isTransient(err); attempt++ {\n    time.Sleep(backoff(attempt))\n    tok, ok, err = c.ImportCopilot(ctx, wsID)\n}","preventionTips":["Check network/VPN connectivity before running import flows","Always pass a cancellable context with a timeout","Surface transport errors to users with actionable messages"],"tags":["network","http","copilot"],"backgroundTag":"http-request-failed","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}