chenhg5/cc-connect · error

platform index must be >= 0

Error message

platform index must be >= 0

What it means

When updating credentials the caller may target a specific platform entry inside the project via opts.PlatformIndex. A negative index is invalid because it cannot address any slice element, so the function rejects it before reading the config. Zero and positive values are accepted (and later bounds-checked against the actual platform list).

Source

Thrown at config/config.go:2033

}

// SaveFeishuPlatformCredentials updates app_id/app_secret for a project's
// Feishu/Lark platform and persists the config atomically.
func SaveFeishuPlatformCredentials(opts FeishuCredentialUpdateOptions) (*FeishuCredentialUpdateResult, 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.AppID) == "" || strings.TrimSpace(opts.AppSecret) == "" {
		return nil, fmt.Errorf("app_id and app_secret are required")
	}
	if opts.PlatformIndex < 0 {
		return nil, fmt.Errorf("platform index must be >= 0")
	}
	if opts.PlatformType != "" && opts.PlatformType != "feishu" && opts.PlatformType != "lark" {
		return nil, fmt.Errorf("invalid platform type %q (want feishu or lark)", opts.PlatformType)
	}

	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

  1. Set opts.PlatformIndex to a valid zero-based index (use 0 for the first platform).
  2. Leave the struct field at 0 instead of -1 when targeting the first Feishu platform.
  3. Clamp/validate the index at the caller: if idx < 0 { idx = 0 } before calling.

Example fix

// before
opts := config.FeishuCredentialUpdateOptions{ProjectName: "p", AppID: "cli_a", AppSecret: "s", PlatformIndex: -1}

// after
opts := config.FeishuCredentialUpdateOptions{ProjectName: "p", AppID: "cli_a", AppSecret: "s", PlatformIndex: 0}
Defensive patterns

Strategy: validation

Validate before calling

if opts.PlatformIndex < 0 {
    opts.PlatformIndex = 0
}

Prevention

When it happens

Trigger: Calling config.SaveFeishuPlatformCredentials with opts.PlatformIndex set to -1 or any negative number, typically from uninitialized zero-value confusion or a 'not specified' sentinel value.

Common situations: Using -1 as a 'first platform' or 'unset' sentinel; forgetting to initialize the field in a dynamically built options struct; off-by-one arithmetic when computing the index upstream.

Related errors


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