Skip to content

Commit

Permalink
Merge pull request #3429 from gabrielcalderon/hacktoberfest
Browse files Browse the repository at this point in the history
Added FROM to explicitly chain exceptions in src/prefect/utilities
  • Loading branch information
joshmeek authored Oct 6, 2020
2 parents c4fbe7e + 726caef commit 35e489d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
5 changes: 5 additions & 0 deletions changes/pr3429.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
enhancement:
- "Added FROM to explicitly chain exceptions in src/prefect/utilities - [#3429](https://github.com/PrefectHQ/prefect/pull/3429)"

contributor:
- "[Juan Calderon-Perez](https://github.com/gabrielcalderon)"
8 changes: 4 additions & 4 deletions src/prefect/utilities/executors.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ def run_with_ctx(*args: Any, _ctx_dict: dict, **kwargs: Any) -> Any:

try:
return fut.result(timeout=timeout)
except FutureTimeout:
raise TimeoutError("Execution timed out.")
except FutureTimeout as exc:
raise TimeoutError("Execution timed out.") from exc


class RecursiveCall(Exception):
Expand Down Expand Up @@ -261,12 +261,12 @@ def wrapper(*args: Any, **kwargs: Any) -> Any:
except RecursiveCall as exc:
try:
call_func = getattr(exc.func, "__wrapped_func__")
except AttributeError:
except AttributeError as attr_error:
raise RecursionError(
"function has not been wrapped to provide tail recursion (func={})".format(
exc.func
)
)
) from attr_error

# there may be multiple nested recursive calls, we should only
# respond to calls for the wrapped function explicitly,
Expand Down
4 changes: 2 additions & 2 deletions src/prefect/utilities/notifications/jira_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

try:
from jira import JIRA
except ImportError:
except ImportError as import_error:
raise ImportError(
'Using `jira_notifier` requires Prefect to be installed with the "jira" extra.'
)
) from import_error

if TYPE_CHECKING:
import prefect.engine.state
Expand Down
6 changes: 4 additions & 2 deletions src/prefect/utilities/notifications/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,10 @@ def add(x, y):
server.login(username, password)
try:
server.sendmail("[email protected]", username, body)
except Exception:
raise ValueError("Email notification for {} failed".format(tracked_obj))
except Exception as exc:
raise ValueError(
"Email notification for {} failed".format(tracked_obj)
) from exc
finally:
server.quit()

Expand Down
8 changes: 4 additions & 4 deletions src/prefect/utilities/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ def _serialize(self, value, attr, obj, **kwargs): # type: ignore
def _validate_json(self, value: Any) -> None:
try:
json.dumps(value)
except TypeError:
raise ValidationError("Value is not JSON-compatible")
except TypeError as type_error:
raise ValidationError("Value is not JSON-compatible") from type_error


class Nested(fields.Nested):
Expand Down Expand Up @@ -382,10 +382,10 @@ def _serialize(self, value, attr, obj, **kwargs): # type: ignore

try:
qual_name = to_qualified_name(value)
except Exception:
except Exception as exc:
raise ValidationError(
f"Invalid function reference, function required, got {value}"
)
) from exc

# sort matches such that the longest / most specific match comes first
valid_bases = sorted(
Expand Down

0 comments on commit 35e489d

Please sign in to comment.