Skip to content

Commit

Permalink
Override __str__ implementation for StageNotFound (iterative#5289)
Browse files Browse the repository at this point in the history
This happens because KeyError quotes the error message.
We'd still like to keep StageNotFound being a KeyError
semantics, but workaround the __str__ implementation.

Mypy was having some problem with the previous `__str__`
override.
  • Loading branch information
skshetry authored Jan 19, 2021
1 parent 372d6f0 commit d8982c6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions dvc/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class DvcException(Exception):

def __init__(self, msg, *args):
assert msg
self.msg = msg
super().__init__(msg, *args)


Expand Down
9 changes: 6 additions & 3 deletions dvc/stage/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,19 @@ def __init__(self, missing_files):
super().__init__(msg)


class StageNotFound(KeyError, DvcException):
__str__ = DvcException.__str__

class StageNotFound(DvcException, KeyError):
def __init__(self, file, name):
self.file = file.relpath
self.name = name
super().__init__(
f"Stage '{self.name}' not found inside '{self.file}' file"
)

def __str__(self):
# `KeyError` quotes the message
# see: https://bugs.python.org/issue2651
return self.msg


class StageNameUnspecified(DvcException):
def __init__(self, file):
Expand Down

0 comments on commit d8982c6

Please sign in to comment.