{"record":{"id":"d8e7bf620f4a718e","repo":"aosabook/500lines","slug":"unknown-object-0-d8e7bf","errorCode":null,"errorMessage":"Unknown object '{0}'","messagePattern":"Unknown object '(.+?)'","errorType":"http","errorClass":"ServerException","httpStatus":404,"severity":"error","filePath":"web-server/code/03-handlers/server-index-page.py","lineNumber":55,"sourceCode":"        return os.path.join(handler.full_path, 'index.html')\n\n    def test(self, handler):\n        return os.path.isdir(handler.full_path) and \\\n               os.path.isfile(self.index_path(handler))\n\n    def act(self, handler):\n        handler.handle_file(self.index_path(handler))\n\n#-------------------------------------------------------------------------------\n\nclass case_always_fail(object):\n    '''Base case if nothing else worked.'''\n\n    def test(self, handler):\n        return True\n\n    def act(self, handler):\n        raise ServerException(\"Unknown object '{0}'\".format(handler.path))\n\n#-------------------------------------------------------------------------------\n\nclass RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):\n    '''\n    If the requested path maps to a file, that file is served.\n    If anything goes wrong, an error page is constructed.\n    '''\n\n    Cases = [case_no_file(),\n             case_existing_file(),\n             case_directory_index_file(),\n             case_always_fail()]\n\n    # How to display an error.\n    Error_Page = \"\"\"\\\n        <html>\n        <body>","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/aosabook/500lines/blob/fba689d101eb5600f5c8f4d7fd79912498e950e2/web-server/code/03-handlers/server-index-page.py#L37-L73","documentation":"Raised by case_always_fail.act in the 03-handlers server-index-page server. case_always_fail.test returns True unconditionally and is the last entry in Cases, so it catches any request that no earlier case matched (not a file, and not a directory containing an index.html via case_directory_index_file).","triggerScenarios":"A request whose full_path exists but matches none of the earlier cases: e.g. a directory with no index.html (case_directory_index_file.test fails), or a special file. The always-fail case then raises ServerException(\"Unknown object\").","commonSituations":"Requesting a directory that lacks an index.html; pointing at a non-file/non-indexable object; an object type for which no case handler is registered.","solutions":["Add an index.html to the requested directory so case_directory_index_file handles it.","Insert a new case class earlier in the Cases list to handle the object type (e.g. directory listing).","Ensure the requested path is a regular file so case_existing_file matches first."],"exampleFix":"// before\n# GET /docs/ with no index.html -> case_always_fail\n// after\n# add docs/index.html, or add a case_directory_no_index_file handler","handlingStrategy":"fallback","validationCode":"# add a case for directories without index BEFORE the always-fail case\nclass case_directory_no_index_file(object):\n    def test(self, handler):\n        return os.path.isdir(handler.full_path)\n    def act(self, handler):\n        handler.list_dir(handler.full_path)\n\n# insert it in Cases before case_always_fail","typeGuard":null,"tryCatchPattern":"try:\n    for case in self.Cases:\n        if case.test(self):\n            case.act(self); break\nexcept ServerException:\n    self.handle_error(msg)","preventionTips":["Add an index.html to directories you want served as pages.","Insert a directory-listing case before case_always_fail.","Order Cases so every object type you support is matched."],"tags":["web-server","http","filesystem","case-dispatch","fallback"],"backgroundTag":null,"analyzedSha":"fba689d101eb5600f5c8f4d7fd79912498e950e2","analyzedAt":"2026-08-13T06:26:32.792Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}