{"record":{"id":"5367b12b19239797","repo":"geekcomputers/Python","slug":"file-local-words-txt-was-not-found","errorCode":null,"errorMessage":"File local_words.txt was not found","messagePattern":"File local_words\\.txt was not found","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"Industrial_developed_hangman/src/hangman/main.py","lineNumber":61,"sourceCode":"    print_function(Style.RESET_ALL + Fore.GREEN + text)\n\n\ndef parse_word_from_local(\n    choice_function: Callable[[List[str]], str] = random.choice,\n) -> str:\n    # noqa: DAR201\n    \"\"\"\n    Parse word from local file.\n\n    :parameter choice_function: Function that will be used to choice a word from file.\n    :returns str: string that contains the word.\n    :raises FileNotFoundError: file to read words not found.\n    \"\"\"\n    try:\n        with open(data_path / \"local_words.txt\", encoding=\"utf8\") as words_file:\n            return choice_function(words_file.read().split(\"\\n\"))\n    except FileNotFoundError:\n        raise FileNotFoundError(\"File local_words.txt was not found\")\n\n\ndef parse_word_from_site(\n    url: str = \"https://random-word-api.herokuapp.com/word\",\n) -> str:\n    # noqa: DAR201\n    \"\"\"\n    Parse word from website.\n\n    :param url: url that word will be parsed from.\n    :return Optional[str]: string that contains the word.\n    :raises ConnectionError: no connection to the internet.\n    :raises RuntimeError: something go wrong with getting the word from site.\n    \"\"\"\n    try:\n        response: requests.Response = requests.get(url, timeout=request_timeout)\n    except ConnectionError:\n        raise ConnectionError(\"There is no connection to the internet\")","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/geekcomputers/Python/blob/40f4cd2652d75ef8e49d76e5c4d431d458712719/Industrial_developed_hangman/src/hangman/main.py#L43-L79","documentation":"parse_word_from_local re-raises FileNotFoundError with a clearer message when local_words.txt (expected next to the module, resolved via data_path) is missing. It is the file-based fallback word source for the industrial hangman game.","triggerScenarios":"get_word called with Source.FROM_FILE when src/hangman/data/local_words.txt does not exist in the installed location; data_path pointing to a wrong directory; packaging that omits the data file.","commonSituations":"pip-installing the package without package_data/include-package-data configured so local_words.txt isn't shipped; running from a different working directory after a move; renaming the data folder.","solutions":["Verify data_path resolves to src/hangman/data and create local_words.txt there","Add the file to package data (pyproject/setup: package-data / MANIFEST.in) so installs include it","Fall back to Source.FROM_INTERNET in get_word when the file is missing","Catch FileNotFoundError at the call site and show a friendly message"],"exampleFix":"# before\nword = get_word(Source.FROM_FILE)\n# after\nif not (data_path / 'local_words.txt').exists():\n    word = get_word(Source.FROM_INTERNET)\nelse:\n    word = get_word(Source.FROM_FILE)","handlingStrategy":"fallback","validationCode":"from pathlib import Path\ndef local_words_available(data_path) -> bool:\n    return (data_path / 'local_words.txt').exists()","typeGuard":null,"tryCatchPattern":"try:\n    word = get_word(Source.FROM_FILE)\nexcept FileNotFoundError:\n    word = get_word(Source.FROM_INTERNET)","preventionTips":["Ship local_words.txt via package-data/MANIFEST.in","Check file existence before selecting the file source","Keep a fallback word list for offline installs"],"tags":["hangman","filenotfound","packaging","data-file"],"backgroundTag":"missing-data-file","analyzedSha":"40f4cd2652d75ef8e49d76e5c4d431d458712719","analyzedAt":"2026-08-27T11:12:20.313Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}