aosabook/500lines · error · ServerException
Unknown object '{0}'
Error message
Unknown object '{0}' What it means
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.
Source
Thrown at web-server/code/03-handlers/server.py:40
class case_existing_file(object):
'''File exists.'''
def test(self, handler):
return os.path.isfile(handler.full_path)
def act(self, handler):
handler.handle_file(handler.full_path)
#-------------------------------------------------------------------------------
class case_always_fail(object):
'''Base case if nothing else worked.'''
def test(self, handler):
return True
def act(self, handler):
raise ServerException("Unknown object '{0}'".format(handler.path))
#-------------------------------------------------------------------------------
class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
'''
If the requested path maps to a file, that file is served.
If anything goes wrong, an error page is constructed.
'''
Cases = [case_no_file(),
case_existing_file(),
case_always_fail()]
# How to display an error.
Error_Page = """\
<html>
<body>
<h1>Error accessing {path}</h1>View on GitHub (pinned to fba689d101)
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.
Example fix
// before # GET /images/ (directory, no handler) -> case_always_fail // after # add case_directory_index_file / case_directory_no_index_file, or request a file
Defensive patterns
Strategy: fallback
Validate before calling
# add a directory case before case_always_fail so dirs are not 'Unknown object'
class case_directory_index_file(object):
def test(self, handler):
return os.path.isdir(handler.full_path)
def act(self, handler):
handler.handle_dir(handler.full_path)
# Cases = [case_no_file(), case_existing_file(), case_directory_index_file(), case_always_fail()] Try / catch
try:
for case in self.Cases:
if case.test(self):
case.act(self); break
except ServerException:
self.handle_error(msg) Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Requesting a directory URL with no directory case registered; special files in the served tree; symlinks isofile rejects.
Related errors
- Unknown object '{0}'
- Unknown object '{0}'
- Unknown object '{0}'
- Unknown object '{0}'
- Unknown object '{0}'
AI-assisted analysis of aosabook/500lines@fba689d101 (2026-08-13).
Data as JSON: /api/errors/c98164adfb0436b9.
Report an issue: GitHub.