From b6a7d3afe3011d1b7c4bcaa943662f110a1d0ddd Mon Sep 17 00:00:00 2001 From: aj Date: Wed, 1 Jul 2020 11:03:43 +0100 Subject: [PATCH] replace exception logging with exception level method --- music/api/api.py | 1 + music/api/player.py | 1 + music/api/spotfm.py | 1 + music/db/database.py | 4 ++-- music/tasks/create_playlist.py | 4 ++-- music/tasks/refresh_lastfm_stats.py | 24 ++++++++++++------------ music/tasks/run_user_playlist.py | 28 ++++++++++++++-------------- music/tasks/update_tag.py | 16 ++++++++-------- 8 files changed, 41 insertions(+), 38 deletions(-) diff --git a/music/api/api.py b/music/api/api.py index 4be0779..41eb20d 100644 --- a/music/api/api.py +++ b/music/api/api.py @@ -371,4 +371,5 @@ def image(user=None): try: return jsonify({'images': net.get_playlist(uri_string=_playlist.uri).images, 'status': 'success'}), 200 except SpotifyNetworkException as e: + logger.exception(f'error occured during {_playlist.name} / {user.username} playlist retrieval') return jsonify({'error': f"spotify error occured: {e.http_code}"}), 404 diff --git a/music/api/player.py b/music/api/player.py index 25e55d5..fd757c0 100644 --- a/music/api/player.py +++ b/music/api/player.py @@ -53,6 +53,7 @@ def play(user=None): else: return jsonify({'error': f"playlist {request_json['playlist_name']} not found"}), 404 except SpotifyNetworkException: + logger.exception(f'error occured during {user.username} playlists retrieval') return jsonify({'error': "playlists not returned"}), 400 elif 'tracks' in request_json: diff --git a/music/api/spotfm.py b/music/api/spotfm.py index 3a8e34c..4a19478 100644 --- a/music/api/spotfm.py +++ b/music/api/spotfm.py @@ -63,6 +63,7 @@ def count(user=None): else: return jsonify({'error': f'playlist {playlist_name} not found'}), 404 except SpotifyNetworkException: + logger.exception(f'error occured during {user.username} playlists retrieval') return jsonify({'error': f'playlist {playlist_name} not found'}), 404 diff --git a/music/db/database.py b/music/db/database.py index 6bbe90d..15871f5 100644 --- a/music/db/database.py +++ b/music/db/database.py @@ -52,8 +52,8 @@ def get_authed_spotify_network(user): try: net.refresh_user_info() - except SpotifyNetworkException as e: - logger.error(f'error refreshing user info for {user.username} = {e}') + except SpotifyNetworkException: + logger.exception(f'error refreshing user info for {user.username}') return net else: diff --git a/music/tasks/create_playlist.py b/music/tasks/create_playlist.py index f031a4e..aaed178 100644 --- a/music/tasks/create_playlist.py +++ b/music/tasks/create_playlist.py @@ -17,6 +17,6 @@ def create_playlist(user, name): try: return net.create_playlist(net.user.user.display_name, name) - except SpotifyNetworkException as e: - logger.error(f'error ocurred {user.username} / {name} - {e}') + except SpotifyNetworkException: + logger.exception(f'error ocurred {user.username} / {name}') return diff --git a/music/tasks/refresh_lastfm_stats.py b/music/tasks/refresh_lastfm_stats.py index 3e0ef40..5293adc 100644 --- a/music/tasks/refresh_lastfm_stats.py +++ b/music/tasks/refresh_lastfm_stats.py @@ -38,8 +38,8 @@ def refresh_lastfm_track_stats(username, playlist_name): try: spotify_playlist = spotnet.get_playlist(uri=Uri(playlist.uri)) - except SpotifyNetworkException as e: - logger.error(f'error retrieving spotify playlist {username} / {playlist_name} - {e}') + except SpotifyNetworkException: + logger.exception(f'error retrieving spotify playlist {username} / {playlist_name}') return track_count = counter.count_playlist(playlist=spotify_playlist) @@ -49,8 +49,8 @@ def refresh_lastfm_track_stats(username, playlist_name): percent = round((track_count * 100) / user_count, 2) else: percent = 0 - except LastFMNetworkException as e: - logger.error(f'error while retrieving user scrobble count - {e}') + except LastFMNetworkException: + logger.exception(f'error while retrieving user scrobble count {username} / {playlist_name}') percent = 0 playlist.lastfm_stat_count = track_count @@ -84,8 +84,8 @@ def refresh_lastfm_album_stats(username, playlist_name): try: spotify_playlist = spotnet.get_playlist(uri=Uri(playlist.uri)) - except SpotifyNetworkException as e: - logger.error(f'error retrieving spotify playlist {username} / {playlist_name} - {e}') + except SpotifyNetworkException: + logger.exception(f'error retrieving spotify playlist {username} / {playlist_name}') return album_count = counter.count_playlist(playlist=spotify_playlist, query_album=True) @@ -95,8 +95,8 @@ def refresh_lastfm_album_stats(username, playlist_name): album_percent = round((album_count * 100) / user_count, 2) else: album_percent = 0 - except LastFMNetworkException as e: - logger.error(f'error while retrieving user scrobble count - {e}') + except LastFMNetworkException: + logger.exception(f'error while retrieving user scrobble count {username} / {playlist_name}') album_percent = 0 playlist.lastfm_stat_album_count = album_count @@ -130,8 +130,8 @@ def refresh_lastfm_artist_stats(username, playlist_name): try: spotify_playlist = spotnet.get_playlist(uri=Uri(playlist.uri)) - except SpotifyNetworkException as e: - logger.error(f'error retrieving spotify playlist {username} / {playlist_name} - {e}') + except SpotifyNetworkException: + logger.exception(f'error retrieving spotify playlist {username} / {playlist_name}') return artist_count = counter.count_playlist(playlist=spotify_playlist, query_artist=True) @@ -141,8 +141,8 @@ def refresh_lastfm_artist_stats(username, playlist_name): artist_percent = round((artist_count * 100) / user_count, 2) else: artist_percent = 0 - except LastFMNetworkException as e: - logger.error(f'error while retrieving user scrobble count - {e}') + except LastFMNetworkException: + logger.exception(f'error while retrieving user scrobble count {username} / {playlist_name}') artist_percent = 0 playlist.lastfm_stat_artist_count = artist_count diff --git a/music/tasks/run_user_playlist.py b/music/tasks/run_user_playlist.py index 7f6ec6e..aa10c53 100644 --- a/music/tasks/run_user_playlist.py +++ b/music/tasks/run_user_playlist.py @@ -52,8 +52,8 @@ def run_user_playlist(username, playlist_name): try: user_playlists = net.get_user_playlists() - except SpotifyNetworkException as e: - logger.error(f'error occured while retrieving playlists {username} / {playlist_name} - {e}') + except SpotifyNetworkException: + logger.exception(f'error occured while retrieving playlists {username} / {playlist_name}') return part_generator = PartGenerator(user=user) @@ -77,8 +77,8 @@ def run_user_playlist(username, playlist_name): playlist_tracks += _tracks else: logger.warning(f'no tracks returned for {uri} {username} / {playlist_name}') - except SpotifyNetworkException as e: - logger.error(f'error occured while retrieving {uri} {username} / {playlist_name} - {e}') + except SpotifyNetworkException: + logger.exception(f'error occured while retrieving {uri} {username} / {playlist_name}') except ValueError: # is a playlist name part_playlist = next((i for i in user_playlists if i.name == part_name), None) @@ -92,8 +92,8 @@ def run_user_playlist(username, playlist_name): playlist_tracks += part_playlist_tracks else: logger.warning(f'no tracks returned for {part_playlist.name} {username} / {playlist_name}') - except SpotifyNetworkException as e: - logger.error(f'error occured while retrieving {part_name} {username} / {playlist_name} - {e}') + except SpotifyNetworkException: + logger.exception(f'error occured while retrieving {part_name} {username} / {playlist_name}') playlist_tracks = remove_local(playlist_tracks) @@ -105,8 +105,8 @@ def run_user_playlist(username, playlist_name): playlist_tracks += library_tracks else: logger.error(f'error getting library tracks {username} / {playlist_name}') - except SpotifyNetworkException as e: - logger.error(f'error occured while retrieving library tracks {username} / {playlist_name} - {e}') + except SpotifyNetworkException: + logger.exception(f'error occured while retrieving library tracks {username} / {playlist_name}') # PLAYLIST TYPE SPECIFIC if playlist.type == 'recents': @@ -159,8 +159,8 @@ def run_user_playlist(username, playlist_name): playlist_tracks += recommendations.tracks else: logger.error(f'error getting recommendations {username} / {playlist_name}') - except SpotifyNetworkException as e: - logger.error(f'error occured while generating recommendations {username} / {playlist_name} - {e}') + except SpotifyNetworkException: + logger.exception(f'error occured while generating recommendations {username} / {playlist_name}') # DEDUPLICATE playlist_tracks = deduplicate_by_name(playlist_tracks) @@ -184,11 +184,11 @@ def run_user_playlist(username, playlist_name): try: net.change_playlist_details(Uri(playlist.uri), description=string) - except SpotifyNetworkException as e: - logger.error(f'error changing description for {username} / {playlist_name} - {e}') + except SpotifyNetworkException: + logger.exception(f'error changing description for {username} / {playlist_name}') - except SpotifyNetworkException as e: - logger.error(f'error executing {username} / {playlist_name} - {e}') + except SpotifyNetworkException: + logger.exception(f'error executing {username} / {playlist_name}') playlist.last_updated = datetime.datetime.utcnow() playlist.update() diff --git a/music/tasks/update_tag.py b/music/tasks/update_tag.py index 2688c70..27d8517 100644 --- a/music/tasks/update_tag.py +++ b/music/tasks/update_tag.py @@ -37,8 +37,8 @@ def update_tag(username, tag_id): tag_count = 0 try: user_scrobbles = net.get_user_scrobble_count() - except LastFMNetworkException as e: - logger.error(f'error retrieving scrobble count - {e}') + except LastFMNetworkException: + logger.exception(f'error retrieving scrobble count {username} / {tag_id}') user_scrobbles = 0 artists = [] @@ -49,8 +49,8 @@ def update_tag(username, tag_id): if net_artist is not None: artist['count'] = net_artist.user_scrobbles tag_count += net_artist.user_scrobbles - except LastFMNetworkException as e: - logger.error(f'error during artist retrieval - {e}') + except LastFMNetworkException: + logger.exception(f'error during artist retrieval {username} / {tag_id}') artists.append(artist) @@ -64,8 +64,8 @@ def update_tag(username, tag_id): if album['artist'].lower() not in [i.lower() for i in [j['name'] for j in artists]]: tag_count += net_album.user_scrobbles - except LastFMNetworkException as e: - logger.error(f'error during album retrieval - {e}') + except LastFMNetworkException: + logger.exception(f'error during album retrieval {username} / {tag_id}') albums.append(album) @@ -79,8 +79,8 @@ def update_tag(username, tag_id): if track['artist'].lower() not in [i.lower() for i in [j['name'] for j in artists]]: tag_count += net_track.user_scrobbles - except LastFMNetworkException as e: - logger.error(f'error during track retrieval - {e}') + except LastFMNetworkException: + logger.exception(f'error during track retrieval {username} / {tag_id}') tracks.append(track)