Skip to content

Our attempted surpression of exception stack traces does not work. #3828

Description

@aknrdureegaesr

Environment

Python Version: 3.11.2

Nikola Version: SHA 3ddf4f6

Operating System: Debian Linux

Description:

We have code _print_exception() in Nikola/__main__.py that tries to print exceptions in a way more digestible to end-users.

I triggered an exception by running some tcp server on port 7890 and then starting nikola serve -p 7890. This was inspired by #3825 .

A format more standard than what we want was output:

nikola serve -p 7890
Traceback (most recent call last):
  File "/home/andreas/comp/nikola-site/venv/lib/python3.11/site-packages/doit/doit_cmd.py", line 294, in run
    return command.parse_execute(args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/andreas/comp/nikola-site/venv/lib/python3.11/site-packages/doit/cmd_base.py", line 150, in parse_execute
    return self.execute(params, args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/andreas/comp/nikola/nikola/plugin_categories.py", line 131, in execute
    return self._execute(options, args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/andreas/comp/nikola/nikola/plugins/command/serve.py", line 147, in _execute
    self.httpd = OurHTTP((options['address'], options['port']), handler_factory)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/socketserver.py", line 456, in __init__
    self.server_bind()
  File "/usr/lib/python3.11/http/server.py", line 136, in server_bind
    socketserver.TCPServer.server_bind(self)
  File "/usr/lib/python3.11/socketserver.py", line 472, in server_bind
    self.socket.bind(self.server_address)
OSError: [Errno 98] Address already in use

Initial analysis

We are running against code in DoItMain.run() which goes like this:

        except Exception:
            if command.pdb:  # pragma: no cover
                import pdb
                pdb.post_mortem(sys.exc_info()[2])
            sys.stderr.write(traceback.format_exc())
            return 3

Idea how to fix:

To not trigger that code, our code should not throw an exception, but instead return 3 itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions