Skip to content

fix: print the verbose traceback to stderr - #8

Open
blaipr wants to merge 1 commit into
ctrliq:mainfrom
blaipr:fix/traceback-to-stderr
Open

fix: print the verbose traceback to stderr#8
blaipr wants to merge 1 commit into
ctrliq:mainfrom
blaipr:fix/traceback-to-stderr

Conversation

@blaipr

@blaipr blaipr commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Summary

ascenderkit/cli/__init__.py printed the traceback for an API error like this:

print(traceback.format_exc(), sys.stderr)

The stream is passed as a value rather than as file, so two things go wrong at once: the traceback lands on stdout, and a repr of the stderr object is appended to it as a second value.

stdout is where the requested document goes. Driving run() with a BadRequest under -v -f json, this is what a caller receives on stdout today:

Traceback (most recent call last):
  ...
ascenderkit.exceptions.BadRequest: Bad Request (400) received - {'detail': 'boom'}
 <_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>
{"detail": "boom"}

stderr is empty, and json.loads on that stream raises. Any ascender ... -v -f json | jq pipeline breaks the moment the server answers with an error. The generic except Exception handler four lines below already writes to stderr, so this was the only branch out of step.

The test passes the stream in rather than relying on a capture fixture, because the default for that parameter is bound to sys.stderr when the module is imported, which is not the object capsys or capfd installs for the duration of a test. It fails on the current code and passes on the fix.

Type of Change

  • Bug fix
  • New feature or enhancement
  • Breaking change
  • Documentation / tooling

Component

CLI (ascenderkit/cli/__init__.py), error handling.

Checklist

  • Tests pass (pytest tests/unit): 352 passed
  • Linting passes (black --check ascenderkit tests setup.py, flake8 ascenderkit)
  • Changelog entry added under Unreleased
  • Documentation updated (if applicable): no documentation covers this output

The stream was passed to print as a value rather than as its `file`, so
the traceback for an API error under -v was written to stdout, with a repr
of the stderr object appended to it as a second value.

stdout is where the requested document goes, so `-f json` and `-f yaml`
came back unparseable to anything downstream the moment the server
answered with an error. The generic handler below this one already routes
to stderr; only this branch did not.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant