Skip to content

Commit

Permalink
Remove nested exception from BadStdStreamFile exception (#3362)
Browse files Browse the repository at this point in the history
Prior to this PR, this exception class had a mandatory nested exception attibute.

This PR removes that exception, because Python already has some nesting mechanisms for exceptions which would serve well enough here: https://docs.python.org/3/tutorial/errors.html#exception-chaining

This change allows exceptions to be optionally chained like any other Python exception; or not chained at all, simplifying one use of BadStdStreamFile where a contrived TypeError was constructed to fill the slot.
  • Loading branch information
benclifford authored and trey-stafford committed Apr 18, 2024
1 parent 06bd899 commit 9f63b39
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion parsl/app/bash.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def open_std_fd(fdname):
os.makedirs(os.path.dirname(fname), exist_ok=True)
fd = open(fname, mode)
except Exception as e:
raise pe.BadStdStreamFile(fname, e)
raise pe.BadStdStreamFile(fname) from e
return fd

std_out = open_std_fd('stdout')
Expand Down
8 changes: 3 additions & 5 deletions parsl/app/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,14 @@ class BadStdStreamFile(ParslError):
Contains:
reason(string)
exception object
"""

def __init__(self, reason: str, exception: Exception) -> None:
super().__init__(reason, exception)
def __init__(self, reason: str) -> None:
super().__init__(reason)
self._reason = reason
self._exception = exception

def __repr__(self) -> str:
return "Bad Stream File: {} Exception: {}".format(self._reason, self._exception)
return "Bad Stream File: {}".format(self._reason)

def __str__(self) -> str:
return self.__repr__()
Expand Down
2 changes: 1 addition & 1 deletion parsl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def get_std_fname_mode(
if len(stdfspec) != 2:
msg = (f"std descriptor {fdname} has incorrect tuple length "
f"{len(stdfspec)}")
raise pe.BadStdStreamFile(msg, TypeError('Bad Tuple Length'))
raise pe.BadStdStreamFile(msg)
fname, mode = stdfspec
return str(fname), mode

Expand Down

0 comments on commit 9f63b39

Please sign in to comment.