chenhg5/cc-connect · error

qq: send image: %w

Error message

qq: send image: %w

What it means

Wraps a failure from callAPI("send_group_msg", ...) inside SendImage when the reply context is a group chat. The OneBot WebSocket API call itself failed — the error carries the underlying cause (ws write failure, invalid response, retcode failure, or 15s timeout).

Source

Thrown at platform/qq/qq.go:488

	rctx, ok := replyCtx.(*replyContext)
	if !ok {
		return fmt.Errorf("qq: SendImage: invalid reply context type %T", replyCtx)
	}

	b64 := base64.StdEncoding.EncodeToString(img.Data)
	segments := []map[string]any{
		{"type": "image", "data": map[string]any{"file": "base64://" + b64}},
	}

	params := map[string]any{
		"message": segments,
	}

	if rctx.messageType == "group" {
		params["group_id"] = rctx.groupID
		_, err := p.callAPI("send_group_msg", params)
		if err != nil {
			return fmt.Errorf("qq: send image: %w", err)
		}
		return nil
	}

	params["user_id"] = rctx.userID
	_, err := p.callAPI("send_private_msg", params)
	if err != nil {
		return fmt.Errorf("qq: send image: %w", err)
	}
	return nil
}

var _ core.ImageSender = (*Platform)(nil)

func (p *Platform) Stop() error {
	if p.cancel != nil {
		p.cancel()
	}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Inspect the wrapped cause: retcode errors name the OneBot failure; timeouts suggest reconnecting the WS session.
  2. Confirm the bot is a member of the target group and has permission to send images there.
  3. If the image is large, use the HTTP API path (callHTTPAPI / upload_group_file) — WS message size limits can break large payloads.
  4. Reconnect the platform (restart Start) if the underlying error is a ws write failure on a stale connection.
  5. Retry once after a transient timeout; OneBot can be briefly unresponsive under load.
Defensive patterns

Strategy: try-catch

Try / catch

if err := p.SendImage(ctx, replyCtx, img); err != nil {
    var apiErr = err.Error()
    switch {
    case strings.Contains(apiErr, "retcode"):
        slog.Error("onebot rejected group image", "err", err) // check bot membership/permissions
    case strings.Contains(apiErr, "timeout"):
        time.Sleep(retryDelay); return p.SendImage(ctx, replyCtx, img)
    case strings.Contains(apiErr, "ws write"):
        return p.reconnect(ctx)
    }
    return err
}

Prevention

When it happens

Trigger: Sending an image to a group when the WebSocket connection is broken (write fails), the OneBot side rejects the action (nonzero retcode, e.g. bot not in group), the response JSON cannot be parsed, or no response arrives within 15 seconds.

Common situations: Bot kicked out of or never added to the target group; OneBot connection dropped mid-send; image base64 payload too large for the WS path; OneBot server busy and slow to respond.

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


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