{"record":{"id":"a2df7df011c3be2e","repo":"chenhg5/cc-connect","slug":"token-is-required","errorCode":null,"errorMessage":"token is required","messagePattern":"token is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/config.go","lineNumber":2397,"sourceCode":"\t\tAddedPlatform:    false,\n\t\tProjectIndex:     len(cfg.Projects),\n\t\tPlatformAbsIndex: 0,\n\t}, nil\n}\n\n// SaveWeixinPlatformCredentials updates token (and optional fields) for a project's Weixin platform.\nfunc SaveWeixinPlatformCredentials(opts WeixinCredentialUpdateOptions) (*WeixinCredentialUpdateResult, error) {\n\tconfigMu.Lock()\n\tdefer configMu.Unlock()\n\n\tif ConfigPath == \"\" {\n\t\treturn nil, fmt.Errorf(\"config path not set\")\n\t}\n\tif strings.TrimSpace(opts.ProjectName) == \"\" {\n\t\treturn nil, fmt.Errorf(\"project name is required\")\n\t}\n\tif strings.TrimSpace(opts.Token) == \"\" {\n\t\treturn nil, fmt.Errorf(\"token is required\")\n\t}\n\tif opts.PlatformIndex < 0 {\n\t\treturn nil, fmt.Errorf(\"platform index must be >= 0\")\n\t}\n\n\tdata, err := os.ReadFile(ConfigPath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"read config: %w\", err)\n\t}\n\traw := string(data)\n\tcfg := &Config{}\n\tif err := toml.Unmarshal(data, cfg); err != nil {\n\t\treturn nil, fmt.Errorf(\"parse config: %w\", err)\n\t}\n\n\tprojectIdx := -1\n\tfor i := range cfg.Projects {\n\t\tif cfg.Projects[i].Name == opts.ProjectName {","sourceCodeStart":2379,"sourceCodeEnd":2415,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/config/config.go#L2379-L2415","documentation":"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.","triggerScenarios":"Calling SaveWeixinPlatformCredentials with WeixinCredentialUpdateOptions{Token: \"\"} — e.g. credential lookup returned empty, user submitted a blank token, or a copy/paste dropped the value.","commonSituations":"Weixin app secret/token not yet provisioned; secret manager lookup failed silently returning empty string; CLI flag for the token not passed.","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."],"exampleFix":"// before\nconfig.SaveWeixinPlatformCredentials(config.WeixinCredentialUpdateOptions{ProjectName: p}) // \"token is required\"\n\n// after\ntok := os.Getenv(\"WEIXIN_TOKEN\")\nif tok == \"\" {\n    return fmt.Errorf(\"WEIXIN_TOKEN must be set\")\n}\nconfig.SaveWeixinPlatformCredentials(config.WeixinCredentialUpdateOptions{ProjectName: p, Token: tok})","handlingStrategy":"validation","validationCode":"if strings.TrimSpace(opts.Token) == \"\" {\n    return fmt.Errorf(\"weixin token must be provided\")\n}","typeGuard":null,"tryCatchPattern":"if err != nil && err.Error() == \"token is required\" {\n    return fmt.Errorf(\"no token supplied: set WEIXIN_TOKEN or pass Token in options\")\n}","preventionTips":["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."],"tags":["config","validation","credentials","go"],"backgroundTag":"missing-required-argument","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}