{"record":{"id":"9675160d36bc437c","repo":"aosabook/500lines","slug":"unknown-object-0-967516","errorCode":null,"errorMessage":"Unknown object '{0}'","messagePattern":"Unknown object '(.+?)'","errorType":"http","errorClass":"ServerException","httpStatus":404,"severity":"error","filePath":"web-server/code/03-handlers/server-no-index-page.py","lineNumber":70,"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               not os.path.isfile(self.index_path(handler))\n\n    def act(self, handler):\n        handler.list_dir(handler.full_path)\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_directory_no_index_file(),\n             case_always_fail()]\n\n    # How to display an error.\n    Error_Page = \"\"\"\\\n        <html>","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/aosabook/500lines/blob/fba689d101eb5600f5c8f4d7fd79912498e950e2/web-server/code/03-handlers/server-no-index-page.py#L52-L88","documentation":"Raised by case_always_fail.act in the 03-handlers server-no-index-page server, the unconditional last case. Because this variant can list directories (case_directory_no_index_file), Unknown object only triggers for objects that are not a file, not a directory, and not missing — i.e. an existing special/unhandled object type.","triggerScenarios":"A request whose full_path exists but is neither a regular file nor a directory (e.g. a device node, socket, or FIFO), so no earlier case's test passes and the always-fail case raises.","commonSituations":"Serving a tree containing special files; symlinks to unusual targets; an object type for which no case is registered.","solutions":["Add a case class earlier in Cases to handle the object type.","Keep only regular files and directories in the served root.","Make the requested path a regular file or directory so an existing case matches."],"exampleFix":"// before\n# request a FIFO in the served tree -> case_always_fail\n// after\n# remove the special file, or add a case that handles it","handlingStrategy":"fallback","validationCode":"# this build already lists directories; Unknown object means a special file type\n# add an explicit guard before dispatch:\nimport os\nif os.path.exists(handler.full_path) and not os.path.isfile(handler.full_path) and not os.path.isdir(handler.full_path):\n    handler.send_error(403, 'Unsupported object')","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":["Keep only regular files and directories in the served root.","Add a dedicated case for any other object type you need.","Order Cases so unhandled types are caught explicitly, not by the fallback."],"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"}