Skip to content

Commit 233c5d3

Browse files
committed
Show notif on invalid remap rules file
1 parent e3f188a commit 233c5d3

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

trakt_scrobbler/commands/log.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,13 @@ class LogOpenCommand(Command):
1111

1212
def handle(self):
1313
from trakt_scrobbler.log_config import LOG_PATH
14+
from trakt_scrobbler.utils import open_file
1415

1516
if not LOG_PATH.exists():
1617
self.line(f'Log file not found at "{LOG_PATH}"', "error")
1718
return 1
1819
self.info(f'Log file is located at: <comment>"{LOG_PATH}"</comment>')
19-
if platform == "darwin":
20-
sp.Popen(["open", LOG_PATH])
21-
elif platform == "linux":
22-
sp.Popen(["xdg-open", LOG_PATH])
23-
elif platform == "win32":
24-
sp.Popen(["explorer", LOG_PATH])
20+
open_file(LOG_PATH)
2521
self.line(
2622
"In case this command doesn't work, "
2723
"manually open the log file from the path."

trakt_scrobbler/mediainfo_remap.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,13 @@ def read_file(file: Path) -> List[RemapRule]:
293293
except FileNotFoundError:
294294
return []
295295
except tomllib.TOMLDecodeError:
296-
logger.exception(f"Invalid TOML in remap_rules file at {file}. Ignoring.")
296+
msg = f"Invalid TOML in remap_rules file at {file}."
297+
logger.exception(msg)
298+
# lazy import
299+
from trakt_scrobbler.notifier import notify, Button
300+
from trakt_scrobbler.utils import open_file
301+
onclick = Button("Open file", on_pressed=lambda: open_file(file))
302+
notify(msg, category="exception", actions=[onclick])
297303
return []
298304
return RemapFile.model_validate(data).rules
299305

trakt_scrobbler/utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging.config
44
import os
55
import re
6+
import subprocess as sp
67
import sys
78
import threading
89
import time
@@ -197,3 +198,15 @@ def convert(self, value, view) -> re.Pattern:
197198
except TypeError as e:
198199
self.fail(u"Couldn't compile regex from '{}'. Error: {}".format(value, e),
199200
view, type_error=True)
201+
202+
203+
def open_file(path):
204+
try:
205+
if sys.platform == "darwin":
206+
sp.Popen(["open", path])
207+
elif sys.platform == "linux":
208+
sp.Popen(["xdg-open", path])
209+
elif sys.platform == "win32":
210+
sp.Popen(["explorer", path])
211+
except (sp.CalledProcessError, OSError):
212+
logger.warning(f"Failed to open file {path}", exc_info=True)

0 commit comments

Comments
 (0)