{"record":{"id":"925e16a3020ce7b1","repo":"aosabook/500lines","slug":"unknown-object-0-925e16","errorCode":null,"errorMessage":"Unknown object '{0}'","messagePattern":"Unknown object '(.+?)'","errorType":"http","errorClass":"ServerException","httpStatus":404,"severity":"error","filePath":"web-server/code/02-serve-static/server.py","lineNumber":44,"sourceCode":"\n    # Classify and handle request.\n    def do_GET(self):\n        try:\n\n            # Figure out what exactly is being requested.\n            full_path = os.getcwd() + self.path\n\n            # It doesn't exist...\n            if not os.path.exists(full_path):\n                raise ServerException(\"'{0}' not found\".format(self.path))\n\n            # ...it's a file...\n            elif os.path.isfile(full_path):\n                self.handle_file(full_path)\n\n            # ...it's something we don't handle.\n            else:\n                raise ServerException(\"Unknown object '{0}'\".format(self.path))\n\n        # Handle errors.\n        except Exception as msg:\n            self.handle_error(msg)\n\n    def handle_file(self, full_path):\n        try:\n            with open(full_path, 'rb') as reader:\n                content = reader.read()\n            self.send_content(content)\n        except IOError as msg:\n            msg = \"'{0}' cannot be read: {1}\".format(self.path, msg)\n            self.handle_error(msg)\n\n    # Handle unknown objects.\n    def handle_error(self, msg):\n        content = self.Error_Page.format(path=self.path, msg=msg)\n        self.send_content(content)","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/aosabook/500lines/blob/fba689d101eb5600f5c8f4d7fd79912498e950e2/web-server/code/02-serve-static/server.py#L26-L62","documentation":"Raised in do_GET of the 02-serve-static server (plain server.py) in the final else branch: the path exists but is not a regular file (os.path.isfile False). Because this variant only handles regular files, any existing non-file object (directory, special file) becomes 'Unknown object'.","triggerScenarios":"A GET request for a path that exists but is not os.path.isfile, e.g. a directory, a FIFO, a device file, or a broken symlink that still reports exists=True.","commonSituations":"Requesting a directory URL; serving a tree containing special files; the always-fallthrough because no directory handler is registered.","solutions":["Request a regular file instead of a directory.","Add directory or index handling (upgrade to a 03-handlers variant).","Ensure only regular files live in the served root for this minimal server."],"exampleFix":"// before\n# GET /data/ (directory) -> Unknown object\n// after\n# register a case_directory handler, or request /data/file.txt","handlingStrategy":"fallback","validationCode":"import os\nfull_path = os.getcwd() + self.path\nif os.path.exists(full_path) and not os.path.isfile(full_path):\n    if os.path.isdir(full_path):\n        self.handle_dir(full_path)   # handle instead of rejecting","typeGuard":null,"tryCatchPattern":"try:\n    # dispatch\nexcept ServerException:\n    self.handle_error(msg)","preventionTips":["Register handlers for directories and other types you support.","Keep only regular files in the served root for this minimal build.","Order checks so existing non-file types never reach the else."],"tags":["web-server","http","filesystem","routing","unsupported-object"],"backgroundTag":null,"analyzedSha":"fba689d101eb5600f5c8f4d7fd79912498e950e2","analyzedAt":"2026-08-13T06:26:32.792Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}