chenhg5/cc-connect · error
token is required
Error message
token is required
What it means
SaveWeixinPlatformCredentials validates at config/config.go:2397 that a non-empty token was supplied, since the whole purpose is storing Weixin credentials. An empty or whitespace-only opts.Token yields this error before any file is read or written.
Source
Thrown at config/config.go:2397
AddedPlatform: false,
ProjectIndex: len(cfg.Projects),
PlatformAbsIndex: 0,
}, nil
}
// SaveWeixinPlatformCredentials updates token (and optional fields) for a project's Weixin platform.
func SaveWeixinPlatformCredentials(opts WeixinCredentialUpdateOptions) (*WeixinCredentialUpdateResult, error) {
configMu.Lock()
defer configMu.Unlock()
if ConfigPath == "" {
return nil, fmt.Errorf("config path not set")
}
if strings.TrimSpace(opts.ProjectName) == "" {
return nil, fmt.Errorf("project name is required")
}
if strings.TrimSpace(opts.Token) == "" {
return nil, fmt.Errorf("token is required")
}
if opts.PlatformIndex < 0 {
return nil, fmt.Errorf("platform index must be >= 0")
}
data, err := os.ReadFile(ConfigPath)
if err != nil {
return nil, fmt.Errorf("read config: %w", err)
}
raw := string(data)
cfg := &Config{}
if err := toml.Unmarshal(data, cfg); err != nil {
return nil, fmt.Errorf("parse config: %w", err)
}
projectIdx := -1
for i := range cfg.Projects {
if cfg.Projects[i].Name == opts.ProjectName {View on GitHub (pinned to 4000b2338a)
Solutions
- Obtain the correct Weixin token and pass it in opts.Token.
- Validate token non-empty at the call site/CLI before invoking (also trims whitespace).
- Fix the upstream source (env var, secret store) that is returning an empty token.
Example fix
// before
config.SaveWeixinPlatformCredentials(config.WeixinCredentialUpdateOptions{ProjectName: p}) // "token is required"
// after
tok := os.Getenv("WEIXIN_TOKEN")
if tok == "" {
return fmt.Errorf("WEIXIN_TOKEN must be set")
}
config.SaveWeixinPlatformCredentials(config.WeixinCredentialUpdateOptions{ProjectName: p, Token: tok}) Defensive patterns
Strategy: validation
Validate before calling
if strings.TrimSpace(opts.Token) == "" {
return fmt.Errorf("weixin token must be provided")
} Try / catch
if err != nil && err.Error() == "token is required" {
return fmt.Errorf("no token supplied: set WEIXIN_TOKEN or pass Token in options")
} Prevention
- Load the token from a secret store and assert non-empty before calling.
- Mark the token as a required CLI flag so missing values fail at parse time.
- Never allow silent empty-string fallbacks when reading credentials.
When it happens
Trigger: Calling SaveWeixinPlatformCredentials with WeixinCredentialUpdateOptions{Token: ""} — e.g. credential lookup returned empty, user submitted a blank token, or a copy/paste dropped the value.
Common situations: Weixin app secret/token not yet provisioned; secret manager lookup failed silently returning empty string; CLI flag for the token not passed.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- app_id and app_secret are required
- tmux: 'session' option is required (name of the tmux session
- config: relay.visibility must be "full", "summary", or "none
- config: at least one [[projects]] entry is required
- config: %s.name is required
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/a2df7df011c3be2e.
Report an issue: GitHub.