chenhg5/cc-connect · error
googlechat: create pubsub client: %w
Error message
googlechat: create pubsub client: %w
What it means
Start creates the Pub/Sub client used to receive Google Chat events, authenticating with the configured token source. When pubsub.NewClient fails (auth error, network error, bad project ID, missing Pub/Sub API), Start cancels its context and returns this wrapped error so the platform fails to start cleanly.
Source
Thrown at platform/googlechat/googlechat.go:163
return "space"
default:
slog.Warn("googlechat: unknown session_scope, using \"space\"", "value", s)
return "space"
}
}
func (p *Platform) Name() string { return "googlechat" }
func (p *Platform) Start(handler core.MessageHandler) error {
p.handler = handler
ctx, cancel := context.WithCancel(context.Background())
p.cancel = cancel
client, err := pubsub.NewClient(ctx, p.projectID, option.WithTokenSource(p.tokenSource))
if err != nil {
cancel()
return fmt.Errorf("googlechat: create pubsub client: %w", err)
}
p.psClient = client
go p.receiveLoop(ctx)
slog.Info("googlechat: started", "subscription", p.subscription, "scope", p.sessionScope)
return nil
}
// receiveLoop runs a streaming pull on the subscription, restarting with a small
// backoff if Receive returns an error while the context is still alive.
func (p *Platform) receiveLoop(ctx context.Context) {
const backoff = 5 * time.Second
sub := p.psClient.Subscriber(p.subscription)
for {
if ctx.Err() != nil {
return
}
err := sub.Receive(ctx, func(_ context.Context, m *pubsub.Message) {View on GitHub (pinned to 4000b2338a)
Solutions
- Enable the Cloud Pub/Sub API: `gcloud services enable pubsub.googleapis.com --project <project>`
- Grant the service account roles/pubsub.subscriber on the subscription and verify the token source credentials are valid and unexpired
- Confirm the project ID matches the project in the subscription resource name and that the network can reach pubsub.googleapis.com:443
Example fix
// before cc-connect start # fails: googlechat: create pubsub client: rpc error: ... permission denied // after gcloud services enable pubsub.googleapis.com gcloud pubsub subscriptions add-iam-policy-binding projects/P/subscriptions/S --member=serviceAccount:bot@P.iam.gserviceaccount.com --role=roles/pubsub.subscriber
Defensive patterns
Strategy: try-catch
Validate before calling
// preflight: verify API + IAM before Start
out, err := exec.Command("gcloud", "pubsub", "subscriptions", "describe", sub, "--format=value(name)").Output() Try / catch
if err := platform.Start(ctx); err != nil {
var pe *googleapi.Error
if errors.As(err, &pe) {
slog.Error("pubsub client failed", "code", pe.Code, "body", pe.Body)
}
return fmt.Errorf("googlechat start: %w", err)
} Prevention
- Enable the Pub/Sub API and grant roles/pubsub.subscriber to the bot's service account during provisioning
- Run a doctor/preflight check that creates (and closes) a pubsub client before daemon start
- Keep service-account key files rotated and confirm GOOGLE_APPLICATION_CREDENTIALS points at a live file
When it happens
Trigger: Calling Start on a googlechat Platform whose projectID is wrong, whose tokenSource credentials lack Pub/Sub permissions or are expired/invalid, when the Pub/Sub API is not enabled for the project, or when network/DNS to Google endpoints fails.
Common situations: Pub/Sub API not enabled in the GCP console; service account missing roles/pubsub.subscriber; GOOGLE_APPLICATION_CREDENTIALS misconfigured or stale key file; typos in the project ID; corporate firewall blocking googleapis.com.
Understand the failure class
Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.
Related errors
- googlechat: subscription must be of the form projects/<proje
- %s: fetch tenant access token: %w
- googlechat: subscription is required (the Pub/Sub subscripti
- googlechat: drain response body: %w
- googlechat: close response body: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/0d9e1074e2613785.
Report an issue: GitHub.