chenhg5/cc-connect · error

weixin: cdn_base_url is empty

Error message

weixin: cdn_base_url is empty

What it means

The CDN upload endpoint base URL (p.cdnBaseURL) is blank, so uploadToWeixinCDN cannot construct the upload request. This is a configuration problem: the WeChat work-platform CDN base URL was never set.

Source

Thrown at platform/weixin/media_outbound.go:60

	rc, ok := replyCtx.(*replyContext)
	if !ok || rc == nil {
		return nil, fmt.Errorf("weixin: invalid reply context")
	}
	if strings.TrimSpace(rc.contextToken) == "" {
		rc.contextToken = p.getContextToken(rc.peerUserID)
	}
	if strings.TrimSpace(rc.contextToken) == "" {
		return nil, fmt.Errorf("weixin: missing context_token for peer %q", rc.peerUserID)
	}
	return rc, nil
}

func (p *Platform) uploadToWeixinCDN(ctx context.Context, to string, plaintext []byte, mediaType int, label string) (*cdnUploadedRef, error) {
	if len(plaintext) == 0 {
		return nil, fmt.Errorf("weixin: %s: empty payload", label)
	}
	if strings.TrimSpace(p.cdnBaseURL) == "" {
		return nil, fmt.Errorf("weixin: cdn_base_url is empty")
	}
	rawSize := len(plaintext)
	aesKey := make([]byte, 16)
	if _, err := rand.Read(aesKey); err != nil {
		return nil, fmt.Errorf("weixin: %s: aes key: %w", label, err)
	}
	filekey := randomHex(16)
	req := getUploadURLRequest{
		Filekey:     filekey,
		MediaType:   mediaType,
		ToUserID:    to,
		Rawsize:     rawSize,
		Rawfilemd5:  md5Hex(plaintext),
		Filesize:    aesECBPaddedSize(rawSize),
		NoNeedThumb: true,
		Aeskey:      hex.EncodeToString(aesKey),
	}
	resp, err := p.api.getUploadURL(ctx, req)

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Set cdn_base_url in the weixin platform section of config.toml to the correct WeChat CDN endpoint.
  2. Validate config at startup (fail fast) so media sends never reach upload with an empty base URL.
  3. Check for whitespace-only values; the check uses TrimSpace, so " " still counts as empty.

Example fix

// before (config.toml)
# cdn_base_url = ""
// after (config.toml)
cdn_base_url = "https://login.weixin.qq.com"  # actual WeChat CDN base URL
Defensive patterns

Strategy: validation

Validate before calling

if strings.TrimSpace(cfg.Weixin.CDNBaseURL) == "" { return errors.New("weixin.cdn_base_url must be set in config.toml") }

Try / catch

if err := p.SendImage(ctx, rc, img); err != nil && strings.Contains(err.Error(), "cdn_base_url is empty") { log.Fatal("weixin platform misconfigured: set cdn_base_url") }

Prevention

When it happens

Trigger: Any SendImage/SendFile/SendAudio call when the platform config omitted cdn_base_url or set it to whitespace.

Common situations: config.toml missing the cdn_base_url key; copy-pasted an example config that leaves it empty; environment-specific config for production WeChat CDN not filled in.

Understand the failure class

Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.

Related errors


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