Skip to main content

improve the error handling for conflicting states

ID
120fc6b
date
2023-05-15 20:07:59+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
cd5c2e5
message
improve the error handling for conflicting states
changed files
1 file, 15 additions, 3 deletions

Changed files

server.py (6988) → server.py (7349)

diff --git a/server.py b/server.py
index 628c446..8271a39 100755
--- a/server.py
+++ b/server.py
@@ -24,7 +24,19 @@ def get_asset_state(asset):
         if alb in {"Approved", "Rejected", "Needs Action"}
     ]
 
-    assert len(state_albums) <= 1
+    if len(state_albums) > 1:
+        print(
+            f"Photo {asset['localIdentifier']} has multiple states! {', '.join(state_albums)}",
+            file=sys.stderr,
+        )
+        subprocess.check_call(
+            [
+                "osascript",
+                "actions/open_photos_app.applescript",
+                asset["localIdentifier"],
+            ]
+        )
+        sys.exit(1)
 
     asset["display_albums"] = [
         alb for alb in asset["albums"] if alb not in state_albums
@@ -209,7 +221,7 @@ def open_photo():
 
 @app.route("/next-unreviewed")
 def next_unreviewed():
-    local_identifier = request.args['before']
+    local_identifier = request.args["before"]
 
     all_assets = photos_data.all_assets
 
@@ -224,7 +236,7 @@ def next_unreviewed():
     ]
     try:
         next_asset_id_to_review = unreviewed_assets[-1]["localIdentifier"]
-        return redirect(url_for('index', localIdentifier=next_asset_id_to_review))
+        return redirect(url_for("index", localIdentifier=next_asset_id_to_review))
     except IndexError:
         return b"", 404