-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvements to parser error handling.
- Loading branch information
1 parent
34c9034
commit 9861892
Showing
3 changed files
with
14 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
""" A module to define custom exceptions """ | ||
""" A module to define metadata parsing exceptions """ | ||
|
||
|
||
class ParserError(Exception): | ||
""" A class to encapsulate all parsing exceptions """ | ||
|
||
def __init__(self, msg_format, *args, **kwargs): | ||
def __init__(self, msg_format, invalid=None, missing=None, **kwargs): | ||
""" | ||
Call Exception with a message formatted with named arguments from | ||
a Dictionary with values by key, or a list of named parameters. | ||
""" | ||
Exception.__init__(self, msg_format.format(*args, **kwargs)) | ||
|
||
super(ParserError, self).__init__(msg_format.format(**kwargs)) | ||
|
||
# Track details about the error for handling downstream | ||
self.invalid = {} if invalid is None else invalid | ||
self.missing = [] if missing is None else missing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters