Skip to content

Commit

Permalink
[pyright] [core] _utils/error (#11695)
Browse files Browse the repository at this point in the history
### Summary & Motivation

Fix a type error in `_utils/error.py`, there is an explanatory comment
in the changes.

### How I Tested These Changes

BK
  • Loading branch information
smackesey committed Jan 15, 2023
1 parent ac05d59 commit 0da0a90
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions python_modules/dagster/dagster/_utils/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from types import TracebackType
from typing import Any, NamedTuple, Optional, Sequence, Tuple, Type, Union

import dagster._check as check
from dagster._serdes import whitelist_for_serdes


Expand All @@ -13,7 +14,7 @@ class SerializableErrorInfo(
[
("message", str),
("stack", Sequence[str]),
("cls_name", str),
("cls_name", Optional[str]),
("cause", Any),
("context", Any),
],
Expand All @@ -27,7 +28,7 @@ def __new__(
cls,
message: str,
stack: Sequence[str],
cls_name: str,
cls_name: Optional[str],
cause: Optional["SerializableErrorInfo"] = None,
context: Optional["SerializableErrorInfo"] = None,
):
Expand Down Expand Up @@ -82,7 +83,14 @@ def serializable_error_info_from_exc_info(
# Whether to forward serialized errors thrown from subprocesses
hoist_user_code_error: Optional[bool] = True,
) -> SerializableErrorInfo:
_exc_type, e, _tb = exc_info
# `sys.exc_info() return Tuple[None, None, None] when there is no exception being processed. We accept this in
# the type signature here since this function is meant to directly receive the return value of
# `sys.exc_info`, but the function should never be called when there is no exception to process.
exc_type, e, tb = exc_info
additional_message = "sys.exc_info() called but no exception available to process."
exc_type = check.not_none(exc_type, additional_message=additional_message)
e = check.not_none(e, additional_message=additional_message)
tb = check.not_none(tb, additional_message=additional_message)
from dagster._core.errors import DagsterUserCodeProcessError

if (
Expand All @@ -92,4 +100,5 @@ def serializable_error_info_from_exc_info(
):
return e.user_code_process_error_infos[0]
else:
return _serializable_error_info_from_tb(traceback.TracebackException(*exc_info))
tb_exc = traceback.TracebackException(exc_type, e, tb)
return _serializable_error_info_from_tb(tb_exc)

0 comments on commit 0da0a90

Please sign in to comment.