{"record":{"id":"f9b81ae97b1362b1","repo":"aosabook/500lines","slug":"0-not-found-f9b81a","errorCode":null,"errorMessage":"'{0}' not found","messagePattern":"'(.+?)' not found","errorType":"http","errorClass":"ServerException","httpStatus":404,"severity":"error","filePath":"web-server/code/05-refactored/server.py","lineNumber":41,"sourceCode":"    def index_path(self, handler):\n        return os.path.join(handler.full_path, 'index.html')\n\n    def test(self, handler):\n        assert False, 'Not implemented.'\n\n    def act(self, handler):\n        assert False, 'Not implemented.'\n\n#-------------------------------------------------------------------------------\n\nclass case_no_file(base_case):\n    '''File or directory does not exist.'''\n\n    def test(self, handler):\n        return not os.path.exists(handler.full_path)\n\n    def act(self, handler):\n        raise ServerException(\"'{0}' not found\".format(handler.path))\n\n#-------------------------------------------------------------------------------\n\nclass case_cgi_file(base_case):\n    '''Something runnable.'''\n\n    def run_cgi(self, handler):\n        cmd = \"python \" + handler.full_path\n        child_stdin, child_stdout = os.popen2(cmd)\n        child_stdin.close()\n        data = child_stdout.read()\n        child_stdout.close()\n        handler.send_content(data)\n\n    def test(self, handler):\n        return os.path.isfile(handler.full_path) and \\\n               handler.full_path.endswith('.py')\n","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/aosabook/500lines/blob/fba689d101eb5600f5c8f4d7fd79912498e950e2/web-server/code/05-refactored/server.py#L23-L59","documentation":"Thrown by case_no_file.act in a teaching web server (the 500 Lines 'A Python Web Server' chapter). The request handler first translates the URL into handler.full_path; case_no_file.test returns True when os.path.exists(handler.full_path) is False, and act raises ServerException with the requested path. The handler's outer try/except catches ServerException and renders a 404 page, so this is the server's canonical 'file or directory does not exist' signal.","triggerScenarios":"Any GET/HEAD request whose resolved filesystem path does not exist: a typo'd URL, a deleted file, a missing directory, or a path whose case does not match the on-disk filename. It fires only after os.path.exists(handler.full_path) returns False, i.e. before any file/directory/CGI case is evaluated.","commonSituations":"Wrong document root configured so full_path points outside the intended tree; URL->path join that mishandles a leading/trailing slash; files renamed or moved after deployment; case-sensitivity mismatch when deploying from macOS/Windows to Linux; a symlink whose target was removed.","solutions":["Verify the resource exists under the configured root: os.path.exists on the exact handler.full_path value.","Check the URL->path translation (the root join) for off-by-one slashes or a missing Root dereference.","Correct the URL casing/typo to match the on-disk filename.","Restore or recreate the missing file/directory, or register it with the server.","If the path legitimately may be absent, add a case before case_no_file to serve a configured fallback."],"exampleFix":"// before: requesting a missing resource\nGET /inde.html HTTP/1.1   ->  raises ServerException(\"'/inde.html' not found\")\n\n// after: validate the path translation before the case loop\nfull_path = os.path.join(Root, handler.path.lstrip('/'))\nif not os.path.exists(full_path):\n    # log the resolved path, fix Root or the URL, then retry","handlingStrategy":"validation","validationCode":"# before issuing/extending a case, confirm the path exists\nimport os\nfull_path = os.path.join(ROOT_DIR, path.lstrip('/'))\nif not os.path.exists(full_path):\n    # log and return a 404 rather than letting ServerException propagate\n    return False","typeGuard":null,"tryCatchPattern":"# if you extend the handler, catch the server's own exception type\ntry:\n    handler.handle_request()\nexcept ServerException as e:\n    log.warning('request failed: %s', e)","preventionTips":["Keep all servable resources under a single ROOT_DIR and serve paths relative to it.","Add an integration test that requests every published URL and asserts 200.","On case-sensitive filesystems, assert filenames match the URL exactly in CI.","Log handler.full_path on failure so resolution bugs are obvious."],"tags":[],"backgroundTag":null,"analyzedSha":"fba689d101eb5600f5c8f4d7fd79912498e950e2","analyzedAt":"2026-08-13T06:26:32.792Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}