{"record":{"id":"af8ae233b0e28b48","repo":"chenhg5/cc-connect","slug":"internal-unknown-mode-q","errorCode":null,"errorMessage":"internal: unknown mode %q","messagePattern":"internal: unknown mode %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cc-connect/weixin.go","lineNumber":230,"sourceCode":"func resolveWeixinSetupMode(requested, token string) (string, error) {\n\tswitch requested {\n\tcase weixinSetupModeAuto:\n\t\tif token != \"\" {\n\t\t\treturn weixinSetupModeBind, nil\n\t\t}\n\t\treturn weixinSetupModeNew, nil\n\tcase weixinSetupModeBind:\n\t\tif token == \"\" {\n\t\t\treturn \"\", errors.New(\"bind mode requires --token\")\n\t\t}\n\t\treturn weixinSetupModeBind, nil\n\tcase weixinSetupModeNew:\n\t\tif token != \"\" {\n\t\t\treturn \"\", errors.New(\"new/QR mode does not accept --token; use `cc-connect weixin bind --token ...`\")\n\t\t}\n\t\treturn weixinSetupModeNew, nil\n\tdefault:\n\t\treturn \"\", fmt.Errorf(\"internal: unknown mode %q\", requested)\n\t}\n}\n\ntype weixinQRLoginOptions struct {\n\tAPIBaseURL string\n\tRouteTag   string\n\tBotType    string\n\tTimeout    time.Duration\n\tQRImage    string\n\tDebug      bool\n}\n\ntype weixinQRLoginResult struct {\n\tBotToken    string\n\tIlinkBotID  string\n\tBaseURL     string\n\tIlinkUserID string\n}","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/cmd/cc-connect/weixin.go#L212-L248","documentation":"resolveWeixinSetupMode maps the user's requested setup mode (--new/--qr or bind) to an internal constant for `cc-connect weixin setup`. If the internal requested value isn't one of the recognized modes, it returns \"internal: unknown mode %q\". This is a defensive programmer-error guard rather than a user-facing input validation failure — invalid flags should be rejected earlier.","triggerScenarios":"runWeixinSetup calls resolveWeixinSetupMode with a mode string that was not set by flag parsing — i.e. a code path constructing the mode value incorrectly, or a new mode constant added in one place but not in the switch.","commonSituations":"A developer adds a new weixin setup subcommand/mode but forgets to add a case to resolveWeixinSetupMode; refactoring renames a mode constant; a plugin or script passes an arbitrary string directly into the setup flow.","solutions":["Inspect the %q value in the message and trace which code path produced it; it should only ever be one of the defined weixinSetupMode* constants.","Add a case (or validation) for the new mode in resolveWeixinSetupMode's switch.","Check flag parsing for `weixin setup` — user input should be validated to a fixed set before reaching this resolver.","Update any external scripts calling setup with a mode string to use supported modes only."],"exampleFix":"// before\nmode := flagGetString(cmd, \"mode\") // arbitrary input flows in\nm, err := resolveWeixinSetupMode(mode)\n\n// after\nif mode != \"\" && mode != weixinSetupModeNew && mode != weixinSetupModeBind {\n    return fmt.Errorf(\"invalid --mode %q\", mode)\n}\nm, err := resolveWeixinSetupMode(mode)","handlingStrategy":"validation","validationCode":"validModes := map[string]bool{\"new\": true, \"bind\": true}\nif !validModes[requested] {\n    return fmt.Errorf(\"invalid setup mode %q; want new|bind\", requested)\n}","typeGuard":null,"tryCatchPattern":"mode, err := resolveWeixinSetupMode(requested)\nif err != nil {\n    return fmt.Errorf(\"weixin setup: %w\", err) // surfaces internal invariant break\n}","preventionTips":["Only pass values produced by the mode constants, never raw user input","Add exhaustive switch lints (e.g. exhauster/exhaustive) for mode enums","When adding a new mode, update the resolver switch in the same change","Cover resolveWeixinSetupMode with table tests enumerating all modes"],"tags":["weixin","internal","mode"],"backgroundTag":"invalid-enum-value","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}