Start exception hierarchy; rename DBNotFound to DatabaseNotFound.
This commit is contained in:
parent
f4d3679063
commit
b7fcad7cc1
3 changed files with 22 additions and 7 deletions
|
@ -423,10 +423,9 @@ def main(argv):
|
|||
args = parser.parse_args(argv)
|
||||
try:
|
||||
args.func(args)
|
||||
except exceptions.DBNotFound as e:
|
||||
message = '"%s" is not an existing database.'
|
||||
except exceptions.DatabaseNotFound as e:
|
||||
message = str(e)
|
||||
message += '\nHave you used any of the other utilities to collect data?'
|
||||
message = message % e.path.absolute_path
|
||||
print(message)
|
||||
return 1
|
||||
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
class DBNotFound(FileNotFoundError):
|
||||
def __init__(self, path):
|
||||
self.path = path
|
||||
class TimesearchException(Exception):
|
||||
'''
|
||||
Base type for all of the Timesearch exceptions.
|
||||
Subtypes should have a class attribute `error_message`. The error message
|
||||
may contain {format} strings which will be formatted using the
|
||||
Exception's constructor arguments.
|
||||
'''
|
||||
error_message = ''
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.given_args = args
|
||||
self.given_kwargs = kwargs
|
||||
self.error_message = self.error_message.format(*args, **kwargs)
|
||||
self.args = (self.error_message, args, kwargs)
|
||||
|
||||
def __str__(self):
|
||||
return self.error_message
|
||||
|
||||
class DatabaseNotFound(TimesearchException, FileNotFoundError):
|
||||
error_message = 'Database file not found: "{}"'
|
||||
|
|
|
@ -124,7 +124,7 @@ class TSDB:
|
|||
self.filepath = pathclass.Path(filepath)
|
||||
if not self.filepath.is_file:
|
||||
if not do_create:
|
||||
raise exceptions.DBNotFound(self.filepath)
|
||||
raise exceptions.DatabaseNotFound(self.filepath)
|
||||
print('New database', self.filepath.relative_path)
|
||||
|
||||
os.makedirs(self.filepath.parent.absolute_path, exist_ok=True)
|
||||
|
|
Loading…
Reference in a new issue