{"record":{"id":"80df21332ccdd6d4","repo":"aosabook/500lines","slug":"unknown-object-0","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-status-code.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, 404)","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/aosabook/500lines/blob/fba689d101eb5600f5c8f4d7fd79912498e950e2/web-server/code/02-serve-static/server-status-code.py#L26-L62","documentation":"Raised in do_GET of the 02-serve-static server-status-code server as the final else branch: full_path exists (os.path.exists True) but is not a regular file (os.path.isfile False). In this variant nothing else is handled, so directories, special files, and sockets all fall through to this ServerException, which the surrounding except routes to handle_error.","triggerScenarios":"A GET request whose path exists but is not a regular file, e.g. requesting a directory (no directory/index handling exists in 02-serve-static), a device node, or a broken-but-present symlink.","commonSituations":"Requesting a directory URL when the server only serves files; serving from a path containing special files; pointing at a symlink that os.path.isfile rejects.","solutions":["Request a concrete file rather than a directory, or add directory/index handling (as the 03-handlers variants do).","Ensure the served tree contains only regular files for this minimal variant.","Add a new branch/case for the object type before the else so it is handled instead of rejected."],"exampleFix":"// before\n# request http://host/images/ (a directory) -> Unknown object\n// after\n# request http://host/images/logo.png (a regular file)","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    # e.g. a directory: handle explicitly instead of reaching 'Unknown object'\n    if os.path.isdir(full_path):\n        self.handle_dir(full_path)","typeGuard":null,"tryCatchPattern":"try:\n    # dispatch\nexcept ServerException:\n    self.handle_error(msg)","preventionTips":["Add a branch for directories before the else so they don't become 'Unknown object'.","Keep only regular files in the served root for the minimal variant.","Map all object types you intend to support to explicit handlers."],"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"}