chenhg5/cc-connect · error

bind mode requires --token (format: app_key:app_secret)

Error message

bind mode requires --token (format: app_key:app_secret)

What it means

resolveYuanbaoBotToken parses the --token flag, which must be in `app_key:app_secret` form. In bind setup mode, an empty token or one without a non-empty key and secret separated by ':' is rejected with this error. Bind mode always requires an existing bot token because it attaches to an already-created Yuanbao bot rather than creating one.

Source

Thrown at cmd/cc-connect/yuanbao.go:130

		os.Exit(1)
	}

	fmt.Printf("✅ Yuanbao bot configured for project %q\n", saveResult.ProjectName)
	fmt.Printf("   Platform: yuanbao (projects[%d].platforms[%d])\n", saveResult.ProjectIndex, saveResult.PlatformAbsIndex)
	if saveResult.AllowFrom != "" {
		fmt.Printf("   allow_from: %s\n", saveResult.AllowFrom)
	}
	fmt.Println()
	fmt.Println("Next: run cc-connect (or restart the daemon) and the platform will")
	fmt.Println("auto-fetch sign-tokens via bot_token and connect over WebSocket.")
}

func resolveYuanbaoBotToken(mode, raw string) (string, error) {
	token := strings.TrimSpace(raw)
	idx := strings.Index(token, ":")
	if token == "" || idx <= 0 || idx >= len(token)-1 {
		if mode == yuanbaoSetupModeBind {
			return "", fmt.Errorf("bind mode requires --token (format: app_key:app_secret)")
		}
		return "", fmt.Errorf("--token is required (format: app_key:app_secret)")
	}
	return token, nil
}

// splitYuanbaoTokenForVerify is the same split as platform/yuanbao's
// splitBotToken, inlined here so the CLI doesn't need to import internal
// helpers of the platform package.
func splitYuanbaoTokenForVerify(raw string) (appKey, appSecret string) {
	raw = strings.TrimSpace(raw)
	idx := strings.Index(raw, ":")
	if idx <= 0 || idx >= len(raw)-1 {
		return "", ""
	}
	return strings.TrimSpace(raw[:idx]), strings.TrimSpace(raw[idx+1:])
}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Pass --token in exactly `app_key:app_secret` form, quoted: --token "mykey:mysecret"
  2. Copy the full token from the Yuanbao bot console including the colon separator
  3. Quote the argument so shells do not split or glob it
  4. If you have no existing bot token, run setup in create mode instead of bind mode

Example fix

// before
cc-connect setup yuanbao --mode bind --token mykey   # missing :secret
// after
cc-connect setup yuanbao --mode bind --token "mykey:mysecret"
Defensive patterns

Strategy: validation

Validate before calling

func validYuanbaoToken(s string) bool {
    k, sec, ok := strings.Cut(strings.TrimSpace(s), ":")
    return ok && k != "" && sec != ""
}
// check before invoking setup bind mode
if mode == "bind" && !validYuanbaoToken(tokenFlag) { /* error out early */ }

Try / catch

if err := runYuanbaoSetup(...); err != nil {
    if strings.Contains(err.Error(), "bind mode requires --token") {
        fmt.Fprintln(os.Stderr, `usage: cc-connect setup yuanbao --mode bind --token "app_key:app_secret"`)
        os.Exit(2)
    }
    return err
}

Prevention

When it happens

Trigger: Running yuanbao setup with mode=bind while --token is missing, empty, whitespace-only, starts with ':', ends with ':', or contains no ':' at all (strings.Index returns -1, failing the idx > 0 and idx < len-1 checks).

Common situations: User forgot the --token flag entirely; pasted only the app_key without the :app_secret part; shell quoting split the token so only part of it arrived; used create mode's looser expectations while running bind.

Understand the failure class

Background: "--flag is required" and "must specify" CLI errors: how missing-required-flag validation works and how to fix it — this error's family across 20 libraries.

Related errors


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