Skip to content

Commit

Permalink
Improve error message for invalid time file
Browse files Browse the repository at this point in the history
See #25
  • Loading branch information
The-Compiler committed Apr 20, 2022
1 parent b62f223 commit 363725a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions journalwatch.py
Expand Up @@ -448,10 +448,16 @@ def parse_since():
if not os.path.exists(TIME_FILE):
return None
with open(TIME_FILE) as f:
since = datetime.fromtimestamp(float(f.read()))
# Add an extra minute just to be sure.
since -= timedelta(minutes=1)
return since
data = f.read()
try:
since = datetime.fromtimestamp(float(data))
except ValueError as e:
raise JournalWatchError(
"Can't parse {}: {} - run 'journalwatch --since all print' to "
"recreate it.".format(TIME_FILE, e))
# Add an extra minute just to be sure.
since -= timedelta(minutes=1)
return since
else:
try:
seconds = int(config.since)
Expand Down

0 comments on commit 363725a

Please sign in to comment.