{"record":{"id":"9d89a904d280bc86","repo":"abi/screenshot-to-code","slug":"invalid-input-mode-input-mode","errorCode":null,"errorMessage":"Invalid input mode: {input_mode}","messagePattern":"Invalid input mode: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"backend/routes/generate_code.py","lineNumber":299,"sourceCode":"        self.throw_error = throw_error\n        self.asset_base_url = asset_base_url\n\n    async def extract_and_validate(self, params: Dict[str, Any]) -> ExtractedParams:\n        \"\"\"Extract and validate all parameters from the request\"\"\"\n        # Read the code config settings (stack) from the request.\n        generated_code_config = params.get(\"generatedCodeConfig\", \"\")\n        if generated_code_config not in get_args(Stack):\n            await self.throw_error(\n                f\"Invalid generated code config: {generated_code_config}\"\n            )\n            raise ValueError(f\"Invalid generated code config: {generated_code_config}\")\n        validated_stack = cast(Stack, generated_code_config)\n\n        # Validate the input mode\n        input_mode = params.get(\"inputMode\")\n        if input_mode not in get_args(InputMode):\n            await self.throw_error(f\"Invalid input mode: {input_mode}\")\n            raise ValueError(f\"Invalid input mode: {input_mode}\")\n        validated_input_mode = cast(InputMode, input_mode)\n\n        openai_api_key = self._get_from_settings_dialog_or_env(\n            params, \"openAiApiKey\", OPENAI_API_KEY\n        )\n\n        # If neither is provided, we throw an error later only if Claude is used.\n        anthropic_api_key = self._get_from_settings_dialog_or_env(\n            params, \"anthropicApiKey\", ANTHROPIC_API_KEY\n        )\n        gemini_api_key = self._get_from_settings_dialog_or_env(\n            params, \"geminiApiKey\", GEMINI_API_KEY\n        )\n        replicate_api_key = self._get_from_settings_dialog_or_env(\n            params, \"replicateApiKey\", REPLICATE_API_KEY\n        )\n\n        # Base URL for OpenAI API","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/abi/screenshot-to-code/blob/d026163f586dfa8c5c10d28c36edd59a9d3b0e88/backend/routes/generate_code.py#L281-L317","documentation":"Error emitted via throw_error in backend/routes/generate_code.py:299 when params['inputMode'] is absent or not a member of the InputMode literal union (screenshot vs import modes). The check runs immediately after stack validation, so a request failing here already passed the stack check.","triggerScenarios":"WebSocket generation request with inputMode missing, undefined, or an unrecognized value (e.g. 'file' instead of the defined import mode name).","commonSituations":"Version skew between frontend and backend after a new input mode was introduced; custom automation clients omitting inputMode; typos in mode strings.","solutions":["Set inputMode explicitly to one of the backend's InputMode values (see the InputMode type the backend defines).","Update the mismatched side (frontend or backend) so both know the same mode names.","For custom clients, log the exact payload before sending to spot undefined fields."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":"const INPUT_MODES = ['screenshot', 'import'] as const;\ntype InputMode = typeof INPUT_MODES[number];\nfunction isInputMode(v: unknown): v is InputMode {\n  return typeof v === 'string' && (INPUT_MODES as readonly string[]).includes(v);\n}","tryCatchPattern":"if (msg.type === 'error' && msg.message.startsWith('Invalid input mode')) {\n  // send a known mode from the backend's union and retry\n}","preventionTips":["Always set inputMode explicitly in WebSocket payloads.","Re-sync client constants after adding new input modes server-side."],"tags":["websocket","validation","input-mode","generate-code"],"backgroundTag":null,"analyzedSha":"d026163f586dfa8c5c10d28c36edd59a9d3b0e88","analyzedAt":"2026-08-14T22:02:06.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}