fix(run): preserve script stdout when an Upload-and-Run file fails - #2171
Merged
Conversation
*Why*
When running a Python file on a cluster ("Upload and Run File"), if the
script raised an exception, any output it printed before failing was lost:
the 1.2 commands API returns only the traceback on an error result and
drops the accumulated stdout. Users saw the traceback with none of the
preceding print output, which makes failures hard to debug.
*What*
- bootstrap.py now buffers the script's stdout while it runs. On an
exception that follows printed output, it emits the captured stdout, a
boundary marker, then a structured JSON traceback (user frames only).
Errors with no prior output re-raise unchanged; success and SystemExit
replay the buffer, so no output is lost.
- ErrorParser.ts gains renderErrorEnvelope() to turn that JSON payload
into renderable frames, plus a shared boundary constant.
- DatabricksRuntime.ts splits the text result on the boundary (stdout
first, then the remapped, clickable traceback) and shares the frame-emit
logic between the new path and the native error path.
The new behaviour triggers only on print-then-crash; successful runs and
errors with no prior output render exactly as before.
*Verification*
- yarn build (tsc) clean; eslint and prettier clean; bootstrap.py compiles.
- Unit tests 4/4 pass (2 new for renderErrorEnvelope).
- End-to-end on a live cluster: print-then-crash preserves stdout and shows
a clickable traceback; success and no-output errors are unchanged.
Co-authored-by: Isaac <no-reply@databricks.com>
Contributor
Author
|
🤖 Integration tests ✅ all 41 test jobs passed for |
misha-db
approved these changes
Sep 4, 2026
rugpanov
enabled auto-merge (squash)
September 4, 2026 09:42
Contributor
|
If integration tests don't run automatically, an authorized user can run them manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
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.
Problem
When running a Python file on a cluster ("Upload and Run File"), if the script raises an exception, any output it printed before failing is lost. The
1.2/commandsexecution API returns only the traceback on an error result and drops the accumulated stdout, so the output panel shows the traceback with none of the precedingprintoutput — making failures hard to debug.Fix
Because a single command yields a single result whose error variant has no stdout field, the captured output has to be preserved where it still exists — in the bootstrap that runs the file.
resources/python/bootstrap.pybuffers the script's stdout while it runs. On an exception that follows printed output, it emits the captured stdout, a boundary marker, then a structured JSON traceback containing only the user's frames. Errors with no prior output re-raise unchanged; successful runs andSystemExit/KeyboardInterruptreplay the buffer, so no output is lost.src/run/ErrorParser.tsaddsrenderErrorEnvelope()to turn that JSON payload into renderable frames (red-highlighted summary line), plus a shared boundary constant.src/run/DatabricksRuntime.tssplits the text result on the boundary — emitting the stdout first, then the traceback remapped to local files (so frames stay clickable) — and shares the frame-emit logic between the new path and the existing error path.The new behaviour triggers only on print-then-crash. Successful runs and errors with no prior output render exactly as before.
Verification
yarn build(fulltsc) clean;eslintandprettierclean;bootstrap.pycompiles.renderErrorEnvelope).bootstrap.py:This pull request and its description were written by Isaac.