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-no-index-page server, the unconditional last case. Because this variant can list directories (case_directory_no_index_file), Unknown object only triggers for objects that are not a file, not a directory, and not missing — i.e. an existing special/unhandled object type.

Source

Thrown at web-server/code/03-handlers/server-no-index-page.py:70

        return os.path.join(handler.full_path, 'index.html')

    def test(self, handler):
        return os.path.isdir(handler.full_path) and \
               not os.path.isfile(self.index_path(handler))

    def act(self, handler):
        handler.list_dir(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_directory_index_file(),
             case_directory_no_index_file(),
             case_always_fail()]

    # How to display an error.
    Error_Page = """\
        <html>

View on GitHub (pinned to fba689d101)

Solutions

  1. Add a case class earlier in Cases to handle the object type.
  2. Keep only regular files and directories in the served root.
  3. Make the requested path a regular file or directory so an existing case matches.

Example fix

// before
# request a FIFO in the served tree -> case_always_fail
// after
# remove the special file, or add a case that handles it
Defensive patterns

Strategy: fallback

Validate before calling

# this build already lists directories; Unknown object means a special file type
# add an explicit guard before dispatch:
import os
if os.path.exists(handler.full_path) and not os.path.isfile(handler.full_path) and not os.path.isdir(handler.full_path):
    handler.send_error(403, 'Unsupported object')

Try / catch

try:
    for case in self.Cases:
        if case.test(self):
            case.act(self); break
except ServerException:
    self.handle_error(msg)

Prevention

When it happens

Trigger: A request whose full_path exists but is neither a regular file nor a directory (e.g. a device node, socket, or FIFO), so no earlier case's test passes and the always-fail case raises.

Common situations: Serving a tree containing special files; symlinks to unusual targets; an object type for which no case is registered.

Related errors


AI-assisted analysis of aosabook/500lines@fba689d101 (2026-08-13). Data as JSON: /api/errors/9675160d36bc437c. Report an issue: GitHub.