{"record":{"id":"5fd2c291b6f1c773","repo":"aosabook/500lines","slug":"unknown-object-0-5fd2c2","errorCode":null,"errorMessage":"Unknown object '{0}'","messagePattern":"Unknown object '(.+?)'","errorType":"http","errorClass":"ServerException","httpStatus":404,"severity":"error","filePath":"web-server/code/04-cgi/server.py","lineNumber":82,"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_cgi_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 = \"\"\"\\","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/aosabook/500lines/blob/fba689d101eb5600f5c8f4d7fd79912498e950e2/web-server/code/04-cgi/server.py#L64-L100","documentation":"Raised by case_always_fail.act in the 04-cgi server, the unconditional last case. After case_cgi_file (.py files), case_existing_file (other files), and case_directory_no_index_file (directories) are tried, anything left — an existing object that is none of those — triggers Unknown object.","triggerScenarios":"A request whose full_path exists but is not a .py file, not another regular file, and not a directory, e.g. a device node, socket, or FIFO; or a directory the directory case declined to list.","commonSituations":"Special files in the served tree; symlinks to unusual targets; an object type no case handles.","solutions":["Add a case class earlier in Cases to handle the object type.","Keep only regular files (.py and otherwise) and directories in the served root.","Make the requested path a type an existing case matches."],"exampleFix":"// before\n# request a special file -> case_always_fail\n// after\n# remove the special file, or add a dedicated case handler","handlingStrategy":"fallback","validationCode":"# after cgi/file/dir cases, guard remaining object types explicitly\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 .py/regular files and directories in the served root.","Add a case for any other object type you must support.","Order Cases so unhandled types are caught explicitly before the fallback."],"tags":["web-server","http","filesystem","case-dispatch","fallback","cgi"],"backgroundTag":null,"analyzedSha":"fba689d101eb5600f5c8f4d7fd79912498e950e2","analyzedAt":"2026-08-13T06:26:32.792Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}