diff --git a/qt/aqt/main.py b/qt/aqt/main.py index 0f2764f66..1acac47d3 100644 --- a/qt/aqt/main.py +++ b/qt/aqt/main.py @@ -301,9 +301,10 @@ class AnkiQt(QMainWindow): self.pendingImport: str | None = None self.restoring_backup = False - # profile not provided on command line? - if not self.pm.name: - # if there's a single profile, load it automatically + # - if a valid profile was provided on commandline, we load it + # - if an invalid profile was provided, we skip this step and show the picker + # - if no profile was provided, we use this step + if not self.pm.name and not self.pm.invalid_profile_provided_on_commandline: profs = self.pm.profiles() name = self.pm.last_loaded_profile_name() if len(profs) == 1: diff --git a/qt/aqt/profiles.py b/qt/aqt/profiles.py index 8a7a2d2ac..28cbd74ae 100644 --- a/qt/aqt/profiles.py +++ b/qt/aqt/profiles.py @@ -123,6 +123,7 @@ class ProfileManager: self.name: str | None = None self.db: DB | None = None self.profile: dict | None = None + self.invalid_profile_provided_on_commandline = False self.base = str(base) def setupMeta(self) -> LoadMetaResult: @@ -131,18 +132,15 @@ class ProfileManager: self.firstRun = res.firstTime return res - # profile load on startup + # -p profile provided on command line. def openProfile(self, profile: str) -> None: - if profile: - if profile not in self.profiles(): - QMessageBox.critical( - None, tr.qt_misc_error(), tr.profiles_profile_does_not_exist() - ) - sys.exit(1) + if profile not in self.profiles(): + self.invalid_profile_provided_on_commandline = True + else: try: self.load(profile) - except TypeError as exc: - raise Exception("Provided profile does not exist.") from exc + except Exception as exc: + self.invalid_profile_provided_on_commandline = True # Profile load/save ######################################################################