From c0b55e64b4e4575b0b9d1af4c51626ea1ab93e5c Mon Sep 17 00:00:00 2001 From: Broque Thomas <26755000+Nezreka@users.noreply.github.com> Date: Thu, 2 Apr 2026 10:57:53 -0700 Subject: [PATCH] Fix Tidal auth crash when download orchestrator not initialized - Add _get_tidal_download_client() helper that checks for None soulseek_client before accessing .tidal attribute - All 3 Tidal download auth endpoints use the helper - Clear error messages: "Download orchestrator not initialized" or "Tidal download client not available" instead of cryptic "'NoneType' object has no attribute 'tidal'" --- web_server.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/web_server.py b/web_server.py index 291d96fb..9318972a 100644 --- a/web_server.py +++ b/web_server.py @@ -30209,25 +30209,33 @@ def deezer_download_test_download(): # TIDAL DOWNLOAD AUTH ENDPOINTS # =================================================================== +def _get_tidal_download_client(): + """Get Tidal download client from the orchestrator, with helpful error if unavailable.""" + if not soulseek_client: + raise RuntimeError("Download orchestrator not initialized — check startup logs for errors") + if not hasattr(soulseek_client, 'tidal') or not soulseek_client.tidal: + raise RuntimeError("Tidal download client not available — ensure tidalapi is installed") + return soulseek_client.tidal + @app.route('/api/tidal/download/auth/start', methods=['POST']) def tidal_download_auth_start(): """Start Tidal device-code OAuth flow for download client.""" try: - tidal_dl = soulseek_client.tidal + tidal_dl = _get_tidal_download_client() result = tidal_dl.start_device_auth() if result: return jsonify({"success": True, **result}) else: return jsonify({"error": "Failed to start Tidal auth. Is tidalapi installed?"}), 500 except Exception as e: - return jsonify({"error": str(e)}), 500 + return jsonify({"error": f"Failed to start Tidal auth: {e}"}), 500 @app.route('/api/tidal/download/auth/check', methods=['GET']) def tidal_download_auth_check(): """Check status of Tidal device-code OAuth flow.""" try: - tidal_dl = soulseek_client.tidal + tidal_dl = _get_tidal_download_client() result = tidal_dl.check_device_auth() return jsonify(result) except Exception as e: @@ -30238,7 +30246,7 @@ def tidal_download_auth_check(): def tidal_download_auth_status(): """Check if Tidal download client is authenticated.""" try: - tidal_dl = soulseek_client.tidal + tidal_dl = _get_tidal_download_client() authenticated = tidal_dl.is_authenticated() return jsonify({"authenticated": authenticated}) except Exception as e: