Repository navigation
[Data] Hide Ray Data internal frames from user-code error tracebacks - #64587
Conversation
Follow-up to ray-project#63023. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Signed-off-by: Aarrya <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request improves the formatting and logging of user-code exceptions in Ray Data by hiding redundant internal execution frames and preventing duplicate traceback logs. The feedback suggests extending the UserCodeException checks in both streaming_executor.py and streaming_executor_state.py to also inspect the exception's cause attribute (e.g., getattr(e, 'cause', None)), ensuring that wrapped exceptions like RayTaskError are correctly identified and their tracebacks are consistently suppressed.
ayushk7102
left a comment
There was a problem hiding this comment.
LGTM! Left some commients
…y __str__ Signed-off-by: Aarrya <[email protected]>
…a-udf-error-logging
For user-code (UDF) errors, Ray Data/Ray Core internal frames are now always hidden from stdout. The `log_internal_stack_trace` flag only controls whether the full driver+worker trace is written to the Ray Data log file (off by default, writing just the cleaned trace). System exceptions still surface the full trace on stdout so users can report Ray bugs. Signed-off-by: Aarrya <[email protected]>
|
Can we also add before and after expandable sections to the PR description? Basically to show how this changes the behaviour of the logger when errors are raised in user code |
revert approval until updated with feedback
…l; trim comments Expand the deprecation warning for the old `log_internal_stack_trace_to_stdout` alias to include a dated removal (January 2027) and an explanation that the behavior has changed: internal Ray Data / Ray Core stack frames are now always omitted from stdout, and `log_internal_stack_trace` controls only whether they are written to the Ray Data log file. Also trim verbose code comments. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Signed-off-by: Aarrya <[email protected]>
…gging Signed-off-by: Aarrya <[email protected]> # Conflicts: # python/ray/data/_internal/execution/streaming_executor_state.py
Head branch was pushed to by a user without write access
Signed-off-by: AarryaSaraf <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit f839dfe. Configure here.
| "written to the Ray Data log file.", | ||
| DeprecationWarning, | ||
| ) | ||
| self.log_internal_stack_trace = value |
There was a problem hiding this comment.
Deprecated alias diverges from field
Medium Severity
The deprecated log_internal_stack_trace_to_stdout setter forwards to log_internal_stack_trace, but assigning log_internal_stack_trace later does not update or remove the legacy attribute stored on the instance. Reading the old name after that can return a stale value, and reading it on a fresh DataContext raises AttributeError because the field was removed from the dataclass.
Reviewed by Cursor Bugbot for commit f839dfe. Configure here.
…ws TODO Make RayTaskError's traceback frame-stripping library-agnostic: extract the Ray Core internal-frame markers into a constant and drive _is_hidden_internal_frame from a marker list, so callers (Ray Data via _RAY_DATA_INTERNAL_FRAME_MARKERS, other libraries in future) can hide their own internal frames on top of the always-hidden core set. Behavior-preserving: RayTaskError.__str__ output is byte-identical before/after across UDF and non-UDF causes. Also re-adds the TODO(windows) note (dropped in an earlier refactor) flagging that frame matching assumes POSIX '/' path separators. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Signed-off-by: Aarrya <[email protected]>
|
🚢 |
…ay-project#64587) ## Description When a UDF passed to a Ray Data transform raises, the error surfaced to the user is buried: the same `RayTaskError`/`UserCodeException` traceback is printed several times (driver propagation, abort log, executor shutdown log), and each copy is padded with Ray Data internal frames (executor / scheduler / planner) the user cannot act on. This PR makes user-code errors concise while leaving genuine internal/system errors fully verbose. Every behavior change is gated on `isinstance(..., UserCodeException)`: - `RayTaskError.__str__` strips `ray/data/_internal/` frames (and their continuation / caret lines) when the root cause is a `UserCodeException`. - The driver-side handler (`omit_traceback_stdout`) logs only the cleaned worker-side trace for user-code errors instead of re-dumping the full driver→worker traceback. - The abort log (`process_completed_tasks`) and the executor shutdown log no longer re-dump the traceback for user-code errors, since it is already logged once (cleaned). **Internal frames are now always omitted from `stdout`.** The renamed `DataContext.log_internal_stack_trace` flag controls only whether the full internal trace is written to the **Ray Data log file** (off by default). The old `log_internal_stack_trace_to_stdout` name still works but is deprecated (removal January 2027) and forwards to the new flag with a `DeprecationWarning`. Internal/system errors are untouched — full tracebacks in every channel. `RAY_DATA_RAISE_ORIGINAL_MAP_EXCEPTION=1` still bypasses the wrapping entirely. ## Before / after Repro — a UDF that divides by zero: ```python import ray def f(row): return {"x": 1 / 0} ray.data.range(1).map(f).take_all() ``` ### Console (stdout) **Before (master):** the traceback is dumped **twice**, each copy padded with internal `map_operator` / `map_transformer` / `plan_udf_map_op` frames: ```text ERROR streaming_executor_state.py:708 -- An exception was raised from a task of operator "Map(f)". ... Traceback (most recent call last): File ".../ray/data/_internal/execution/streaming_executor_state.py", line 673, in process_completed_tasks bytes_read = task.on_data_ready( File ".../ray/data/_internal/execution/interfaces/physical_operator.py", line 276, in on_data_ready raise ex from None ... (worker.py / auto_init_hook / client_mode_hook frames) ... ray.exceptions.RayTaskError(UserCodeException): ray::Map(f)() (pid=5427, ip=127.0.0.1) File ".../scratchpad/repro.py", line 11, in f return {"x": 1 / 0} ZeroDivisionError: division by zero The above exception was the direct cause of the following exception: ray::Map(f)() (pid=5427, ip=127.0.0.1) File ".../ray/data/_internal/execution/operators/map_operator.py", line 855, in _map_task File ".../ray/data/_internal/execution/operators/map_transformer.py", line 221, in __next__ File ".../ray/data/_internal/planner/plan_udf_map_op.py", line 470, in _wrapped_udf_map_fn _try_wrap_udf_exception(e) File ".../ray/data/_internal/planner/plan_udf_map_op.py", line 486, in _try_wrap_udf_exception raise UserCodeException("UDF failed to process a data block.") from e ray.exceptions.UserCodeException: UDF failed to process a data block. INFO streaming_executor.py:338 --⚠️ Dataset dataset_1_0 execution failed ERROR exceptions.py:63 -- Exception occurred in user code ... set `DataContext.log_internal_stack_trace_to_stdout` to True. Traceback (most recent call last): ... (the ENTIRE traceback above is repeated a second time) ... ray.exceptions.UserCodeException: UDF failed to process a data block. ``` **After (identical for `log_internal_stack_trace` = False *or* True):** printed once, only the user's frame: ```text ERROR exceptions.py:68 -- Exception occurred in user code, with the abbreviated stack trace below. The Ray Data internal stack frames are omitted from stdout. To also write the full stack trace to the Ray Data log file at `.../logs/ray-data`, set `DataContext.log_internal_stack_trace` to True. Traceback (most recent call last): File ".../scratchpad/repro.py", line 13, in <module> ray.data.range(1).map(f).take_all() ... (a few driver frames) ... File ".../ray/data/exceptions.py", line 101, in handle_trace raise e.with_traceback(None) ray.exceptions.RayTaskError(UserCodeException): ray::Map(f)() (pid=3655, ip=127.0.0.1) File ".../scratchpad/repro.py", line 11, in f return {"x": 1 / 0} ~~^~~ ZeroDivisionError: division by zero The above exception was the direct cause of the following exception: ray::Map(f)() (pid=3655, ip=127.0.0.1) ray.exceptions.UserCodeException: UDF failed to process a data block. ``` (With `log_internal_stack_trace=True` the stdout is the same, minus the one "Exception occurred in user code" advisory line — the flag never adds internal frames to stdout.) ### Log file (`.../logs/ray-data/ray-data.log`) **Before (master):** the log file always contained the full driver + worker trace (internal frames included). **After, `log_internal_stack_trace=False` (default):** only the cleaned worker-side trace, no internal frames: ```text ERROR exceptions.py:95 -- Full stack trace: ray::Map(f)() (pid=3655, ip=127.0.0.1) File ".../scratchpad/repro.py", line 11, in f return {"x": 1 / 0} ~~^~~ ZeroDivisionError: division by zero The above exception was the direct cause of the following exception: ray::Map(f)() (pid=3655, ip=127.0.0.1) ray.exceptions.UserCodeException: UDF failed to process a data block. ``` **After, `log_internal_stack_trace=True`:** the full driver + worker trace is restored to the log file (equivalent to master's old log-file content), while stdout stays clean: ```text ERROR exceptions.py:91 -- Full stack trace: Traceback (most recent call last): File ".../ray/data/exceptions.py", line 49, in handle_trace File ".../ray/data/dataset.py", line 7748, in _execute_to_iterator File ".../ray/data/_internal/execution/streaming_executor.py", line 767, in get_next File ".../ray/data/_internal/execution/streaming_executor_state.py", line 502, in get_output_blocking File ".../ray/data/_internal/execution/streaming_executor_state.py", line 723, in process_completed_tasks File ".../ray/data/_internal/execution/interfaces/physical_operator.py", line 284, in on_data_ready File ".../ray/_private/worker.py", line 1050, in get_objects raise value.as_instanceof_cause() ray.exceptions.RayTaskError(UserCodeException): ray::Map(f)() (pid=4137, ip=127.0.0.1) File ".../scratchpad/repro.py", line 11, in f return {"x": 1 / 0} ~~^~~ ZeroDivisionError: division by zero The above exception was the direct cause of the following exception: ray::Map(f)() (pid=4137, ip=127.0.0.1) ray.exceptions.UserCodeException: UDF failed to process a data block. ``` ## Related issues Follow-up to ray-project#63023. ## Additional information Extends `test_exceptions.py` to assert: the "Full stack trace:" record is always hidden from stdout (`hide=True`) for user-code errors; the record carries only the cleaned inlined trace by default (`exc_info is None`) and the full traceback via `exc_info` when `log_internal_stack_trace=True`; system exceptions keep `hide=False`; and the deprecated `log_internal_stack_trace_to_stdout` alias still forwards with a `DeprecationWarning`. --------- Signed-off-by: Aarrya <[email protected]> Signed-off-by: AarryaSaraf <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> Co-authored-by: Ayush Kumar <[email protected]> Signed-off-by: 400Ping <[email protected]>


Description
When a UDF passed to a Ray Data transform raises, the error surfaced to the
user is buried: the same
RayTaskError/UserCodeExceptiontraceback is printedseveral times (driver propagation, abort log, executor shutdown log), and each
copy is padded with Ray Data internal frames (executor / scheduler / planner)
the user cannot act on.
This PR makes user-code errors concise while leaving genuine internal/system
errors fully verbose. Every behavior change is gated on
isinstance(..., UserCodeException):RayTaskError.__str__stripsray/data/_internal/frames (and theircontinuation / caret lines) when the root cause is a
UserCodeException.omit_traceback_stdout) logs only the cleanedworker-side trace for user-code errors instead of re-dumping the full
driver→worker traceback.
process_completed_tasks) and the executor shutdown log nolonger re-dump the traceback for user-code errors, since it is already
logged once (cleaned).
Internal frames are now always omitted from
stdout. The renamedDataContext.log_internal_stack_traceflag controls only whether the fullinternal trace is written to the Ray Data log file (off by default). The
old
log_internal_stack_trace_to_stdoutname still works but is deprecated(removal January 2027) and forwards to the new flag with a
DeprecationWarning.Internal/system errors are untouched — full tracebacks in every channel.
RAY_DATA_RAISE_ORIGINAL_MAP_EXCEPTION=1still bypasses the wrapping entirely.Before / after
Repro — a UDF that divides by zero:
Console (stdout)
Before (master): the traceback is dumped twice, each copy padded with
internal
map_operator/map_transformer/plan_udf_map_opframes:After (identical for
log_internal_stack_trace= False or True): printedonce, only the user's frame:
(With
log_internal_stack_trace=Truethe stdout is the same, minus the one"Exception occurred in user code" advisory line — the flag never adds internal
frames to stdout.)
Log file (
.../logs/ray-data/ray-data.log)Before (master): the log file always contained the full driver + worker
trace (internal frames included).
After,
log_internal_stack_trace=False(default): only the cleanedworker-side trace, no internal frames:
After,
log_internal_stack_trace=True: the full driver + worker trace isrestored to the log file (equivalent to master's old log-file content), while
stdout stays clean:
Related issues
Follow-up to #63023.
Additional information
Extends
test_exceptions.pyto assert: the "Full stack trace:" record is alwayshidden from stdout (
hide=True) for user-code errors; the record carries onlythe cleaned inlined trace by default (
exc_info is None) and the full tracebackvia
exc_infowhenlog_internal_stack_trace=True; system exceptions keephide=False; and the deprecatedlog_internal_stack_trace_to_stdoutalias stillforwards with a
DeprecationWarning.