chenhg5/cc-connect · error

subscribe failed: errcode=%d errmsg=%s

Error message

subscribe failed: errcode=%d errmsg=%s

What it means

The subscribe response arrived but carried a non-zero errcode, meaning the WeCom server explicitly rejected the subscription. The error includes the server's errcode and errmsg. Unlike read failures, this is an application-level rejection — the connection itself works.

Source

Thrown at platform/wecom/websocket.go:251

			"bot_id": p.botID,
			"secret": p.secret,
		},
	}
	if err := p.writeJSON(subFrame); err != nil {
		return fmt.Errorf("subscribe: %w", err)
	}

	// Read subscribe response: { headers: { req_id }, errcode: 0, errmsg: "ok" }
	var subResp wsFrame
	if err := conn.ReadJSON(&subResp); err != nil {
		return fmt.Errorf("subscribe response: %w", err)
	}
	if subResp.ErrCode == nil || *subResp.ErrCode != 0 {
		errCode := 0
		if subResp.ErrCode != nil {
			errCode = *subResp.ErrCode
		}
		return fmt.Errorf("subscribe failed: errcode=%d errmsg=%s", errCode, subResp.ErrMsg)
	}
	slog.Info("wecom-ws: subscribed successfully", "bot_id", p.botID)
	p.missedPong.Store(0)

	// Start heartbeat goroutine
	heartCtx, heartCancel := context.WithCancel(p.ctx)
	defer heartCancel()
	go p.heartbeat(heartCtx, conn)

	// Read loop
	for {
		select {
		case <-p.ctx.Done():
			return p.ctx.Err()
		default:
		}

		_, raw, err := conn.ReadMessage()

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Read errcode/errmsg in the error and map it via WeCom docs (usually auth/credential related).
  2. Re-copy bot_id and bot_secret from the WeCom admin console into config.toml and restart.
  3. Confirm the bot is enabled and its IP allowlist includes this host.
  4. Regenerate the secret if it may have been revoked, then update config.

Example fix

// before
bot_secret = "old-revoked-secret"

// after
bot_secret = "newly-regenerated-secret"
Defensive patterns

Strategy: validation

Validate before calling

tok := wecom.GetToken(botID, secret)
if tok.ErrCode != 0 { return fmt.Errorf("invalid wecom credentials: errcode=%d", tok.ErrCode) }

Type guard

null

Try / catch

err := platform.Start(ctx)
var subErr *SubscribeError
if errors.As(err, &subErr) && isAuthCode(subErr.Code) {
	rotateSecret(); restart()
}

Prevention

When it happens

Trigger: Server returns errcode != 0 in the subscribe response, typically due to invalid bot_id/bot_secret, bot disabled/deleted in the WeCom admin console, or IP not in the bot's allowlist.

Common situations: Rotated secret in config not updated; bot credentials from a different WeCom org; bot deactivated for inactivity; errcode indicating expired/invalid secret after a security policy change.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/5bfba99c15048682. Report an issue: GitHub.