debug: wrap Song init in try-except, log Public methods before any Song attempts

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
HoneyandClaude Sonnet 4.6 committed 2026-05-13 01:21:19 +02:00
1 parent 5d0c5ec6eb
commit 76785a4eaa
1 file changed
+18 -17
+18 -17
View File
@@ -64,25 +64,26 @@ def resolve(sp_type, sp_id):
url = f'https://open.spotify.com/{sp_type}/{sp_id}'
if sp_type == 'track':
# Song(url) stores url as the client object, then get_song_info() or init
# tries to call url.login which fails. Try: Song(url) + get_song_info(url),
# then Song(url) + get_song_info(), log methods as last resort.
song = sp_mod.Song(url)
song_methods = [m for m in dir(song) if not m.startswith('_')]
eprint(f'[spotapi] Song methods: {song_methods}')
raw = None
for attempt in [
lambda: song.get_song_info(url),
lambda: song.get_song_info(),
]:
try:
raw = attempt()
break
except Exception as e:
eprint(f'[spotapi] track attempt failed: {type(e).__name__}: {e}')
if raw is None:
# Log Public methods first so we always see them regardless of Song failures
pub = sp_mod.Public()
eprint(f'[spotapi] Public methods: {[m for m in dir(pub) if not m.startswith("_")]}')
raw = None
# Try every plausible call pattern — Song requires a Login session, not a URL,
# so we also try Public directly in case it exposes track methods.
attempts = [
('Public(url).get_song_info()', lambda: sp_mod.Public(url).get_song_info()),
('Public().get_song_info(url)', lambda: sp_mod.Public().get_song_info(url)),
('Song(url).get_song_info(url)', lambda: sp_mod.Song(url).get_song_info(url)),
('Song(url).get_song_info()', lambda: sp_mod.Song(url).get_song_info()),
]
for label, fn in attempts:
try:
raw = fn()
eprint(f'[spotapi] track: {label} succeeded')
break
except Exception as e:
eprint(f'[spotapi] track [{label}] failed: {type(e).__name__}: {e}')
if raw is None:
raise Exception('Song resolution: all attempts failed')
eprint(f'[spotapi] track raw type={type(raw).__name__} keys={list(raw.keys()) if isinstance(raw, dict) else "?"}')
if isinstance(raw, dict):