{"record":{"id":"c98164adfb0436b9","repo":"aosabook/500lines","slug":"unknown-object-0-c98164","errorCode":null,"errorMessage":"Unknown object '{0}'","messagePattern":"Unknown object '(.+?)'","errorType":"http","errorClass":"ServerException","httpStatus":404,"severity":"error","filePath":"web-server/code/03-handlers/server.py","lineNumber":40,"sourceCode":"class case_existing_file(object):\n    '''File exists.'''\n\n    def test(self, handler):\n        return os.path.isfile(handler.full_path)\n\n    def act(self, handler):\n        handler.handle_file(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_always_fail()]\n\n    # How to display an error.\n    Error_Page = \"\"\"\\\n        <html>\n        <body>\n        <h1>Error accessing {path}</h1>","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/aosabook/500lines/blob/fba689d101eb5600f5c8f4d7fd79912498e950e2/web-server/code/03-handlers/server.py#L22-L58","documentation":"Raised by case_always_fail.act in the 03-handlers server (minimal case-dispatch build). As the unconditional last case, it fires for any existing object that is not a regular file (this build has no directory handling), e.g. a directory request.","triggerScenarios":"A request whose full_path exists but is not a regular file (os.path.isfile False), so case_existing_file.test fails and the always-fail case is reached.","commonSituations":"Requesting a directory URL with no directory case registered; special files in the served tree; symlinks isofile rejects.","solutions":["Request a regular file rather than a directory.","Add a directory/index case to the Cases list before case_always_fail.","Keep only regular files under the served root."],"exampleFix":"// before\n# GET /images/ (directory, no handler) -> case_always_fail\n// after\n# add case_directory_index_file / case_directory_no_index_file, or request a file","handlingStrategy":"fallback","validationCode":"# add a directory case before case_always_fail so dirs are not 'Unknown object'\nclass case_directory_index_file(object):\n    def test(self, handler):\n        return os.path.isdir(handler.full_path)\n    def act(self, handler):\n        handler.handle_dir(handler.full_path)\n\n# Cases = [case_no_file(), case_existing_file(), case_directory_index_file(), 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":["Register a directory/index case before the always-fail case.","Keep only regular files in the served root if no dir handler is added.","Order Cases so all supported object types are 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"}