{"record":{"id":"9d43b9dddb696b9d","repo":"geekcomputers/Python","slug":"non-existing-enum","errorCode":null,"errorMessage":"Non existing enum","messagePattern":"Non existing enum","errorType":"exception","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"Industrial_developed_hangman/src/hangman/main.py","lineNumber":119,"sourceCode":"        self._word_string_to_show = \"\"\n        self._guess_attempts_coefficient = 2\n        self._print_function = pr_func\n        self._input_function = in_func\n        self._choice_function = ch_func\n\n    def get_word(self) -> str:\n        # noqa: DAR201\n        \"\"\"\n        Parse word(wrapper for local and web parse).\n\n        :returns str: string that contains the word.\n        :raises AttributeError: Not existing enum\n        \"\"\"\n        if self._source == Source.FROM_INTERNET:\n            return parse_word_from_site()\n        elif self._source == Source.FROM_FILE:\n            return parse_word_from_local(self._choice_function)\n        raise AttributeError(\"Non existing enum\")\n\n    def user_lose(self) -> None:\n        \"\"\"Print text for end of game and exits.\"\"\"\n        print_wrong(\n            f\"YOU LOST(the word was '{self._answer_word}')\", self._print_function\n        )  # noqa:WPS305\n\n    def user_win(self) -> None:\n        \"\"\"Print text for end of game and exits.\"\"\"\n        print_wrong(f\"{self._word_string_to_show} YOU WON\", self._print_function)  # noqa:WPS305\n\n    def game_process(self, user_character: str) -> bool:\n        # noqa: DAR201\n        \"\"\"\n        Process user input.\n\n        :parameter user_character: User character.\n        :returns bool: state of game.","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/geekcomputers/Python/blob/40f4cd2652d75ef8e49d76e5c4d431d458712719/Industrial_developed_hangman/src/hangman/main.py#L101-L137","documentation":"get_word dispatches on a Source enum; if self._source matches neither FROM_INTERNET nor FROM_FILE it raises AttributeError('Non existing enum'). This guards against an invalid, stale, or mocked enum value reaching the dispatcher.","triggerScenarios":"Constructing MainProcess with a Source member added later/removed, passing a raw string or int instead of a Source enum, or tests passing sentinel values. Because the checks are if/elif over two members, any third value falls through.","commonSituations":"Extending Source with a new member (e.g. FROM_DATABASE) without updating get_word; serializing/deserializing the enum through JSON so it becomes a string; tests passing fake source values.","solutions":["Always pass a Source enum member: MainProcess(Source.FROM_FILE)","If Source came from storage/JSON, coerce it back: Source(value) before use","When adding enum members, update get_word's dispatch (prefer match or dict dispatch)","In tests, patch parse_word_from_site instead of inventing fake enum values"],"exampleFix":"# before\nsource = 'internet'  # raw string\nproc = MainProcess(source)\n# after\nfrom hangman.main import Source\nproc = MainProcess(Source.FROM_INTERNET)","handlingStrategy":"type-guard","validationCode":"from hangman.main import Source\nassert source in (Source.FROM_INTERNET, Source.FROM_FILE)","typeGuard":"from enum import Enum\ndef is_valid_source(value) -> bool:\n    return isinstance(value, Enum) and value in set(Source)","tryCatchPattern":"try:\n    word = get_word()\nexcept AttributeError:\n    print('invalid word source configured')","preventionTips":["Only pass Source enum members, never raw strings/ints","Coerce deserialized values with Source(value)","Update get_word dispatch whenever Source gains new members"],"tags":["hangman","enum","dispatch","attribute-error"],"backgroundTag":"invalid-enum-value","analyzedSha":"40f4cd2652d75ef8e49d76e5c4d431d458712719","analyzedAt":"2026-08-27T11:12:20.313Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}