Send console errors to stderr instead of stdout - #1792
Merged
pierrecamilleri merged 6 commits intoJul 27, 2026
Conversation
print_error and print_exception rendered onto the caller's stdout console, so redirecting stdout captured the error panel: `frictionless describe data.csv --json > out.json` wrote the red panel into out.json whenever the source could not be read. Both now print to a module-level stderr console, including the debug traceback path. extract's "No rows found" panel used print_error purely for its styling, but it is part of the report body on a successful run and sits between the rendered tables, so it moves to a new print_panel helper and stays on stdout. The five console tests that asserted error text on stdout now assert on stderr, which is the behaviour being fixed.
pierrecamilleri
approved these changes
Jul 27, 2026
Collaborator
|
Thanks, I additionnaly removed the wordy LLM comments, and adapted the tests for python 3.9 support. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
print_errorandprint_exceptionrendered onto whatever console the command passed in, and every command builds a plain stdoutConsole(). So the reporter's case does this:Both helpers now print to a module-level
Console(stderr=True), including thedebug=Truepath, which calledconsole.print_exception()and would otherwise have kept leaking tracebacks to stdout.@pierrecamilleri — your comment named
helpers.pyas the fix locus, which is right, but there is one call site in there that must not move:extract.py:233callsprint_error(console, note="No rows found", title="Empty")from inside the table-rendering loop, afterconsole.rule("[bold]Tables")and followed bycontinue. That is report content on a successful run (exit 0) usingprint_errorpurely for the red panel styling. Sending it to stderr would tear it out of the sequence of tables it sits between. So it moves to a newprint_panelhelper that renders on the passed console. Verified:frictionless extract empty.csvstill prints "No rows found" to stdout, exit 0, with stderr empty.I kept the
consoleparameter on both helpers rather than dropping it and touching all 31 call sites across 12 command files. It is unused inprint_error/print_exceptionnow, which is a little untidy — happy to remove it and update the call sites if you'd prefer that diff.Tests. Five console tests asserted error text on
result.stdout; they now assert onresult.stderr, which is precisely the behaviour under change:test_describe.py::test_console_describe_error_not_foundtest_transform.py::test_console_transform_error_not_found_source_issue_814test_validate.py::test_console_validate_single_invalid_resource_221test_extract.py::test_console_extract_single_invalid_resourcetest_extract.py::test_console_extract_single_valid_resource_invalid_packageTwo new tests pin the separation directly: an error run must leave stdout completely empty while stderr carries the message, and a successful
--jsonrun must still produce parseable JSON on stdout with stderr empty. Reverting the source while keeping the tests fails the first of those; the second passes either way, deliberately, so it catches over-correction.pytest frictionless/consolegoes from 4 failed / 85 passed to 4 failed / 92 passed — the four are pre-existingdialect_sheet_optionfailures unrelated to this change and present on unmodifiedmain.ruff checkreports the same counts on both files I touched before and after (182 and 33), so this adds no new lint findings, though note those counts are from a newer ruff than the pinned one.I did not add a CHANGELOG entry since there is no unreleased section, but this is a user-visible behaviour change for anyone parsing stdout, so say the word if you want one.