Skip to content

Commit

Permalink
Flake8 QA
Browse files Browse the repository at this point in the history
- Ignoring raising BaseExceptions; we can't raise an exception here as it will abort the rest of the execution (in this case, the HTTP or WS request)
  • Loading branch information
jaedb committed Mar 25, 2024
1 parent 13f93fb commit 7718bd2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
26 changes: 13 additions & 13 deletions mopidy_iris/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def load_from_file(self, name):
content = pickle.load(f)
f.close()
return content
except Exception:
except BaseException: # noqa: B036
if name == "pinned":
return []
else:
Expand All @@ -101,7 +101,7 @@ def save_to_file(self, dict, name):
with file_path.open("wb") as f:
pickle.dump(dict, f, pickle.HIGHEST_PROTOCOL)
pickle.close()
except Exception:
except BaseException: # noqa: B036
return False

##
Expand Down Expand Up @@ -139,7 +139,7 @@ def digest_protocol(self, protocol):
generated = False

# invalid, so just create a default connection, and auto-generate an ID
except BaseException:
except BaseException: # noqa: B036
client_id = self.generateGuid()
connection_id = self.generateGuid()
username = "Anonymous"
Expand Down Expand Up @@ -198,7 +198,7 @@ def send_message(self, *args, **kwargs):
callback(response)
else:
return response
except BaseException:
except BaseException: # noqa: B036
error = "Failed to send message to " + data["recipient"]
logger.error(error)

Expand Down Expand Up @@ -331,7 +331,7 @@ def remove_connection(self, connection_id):
"params": {"connection": client},
}
)
except BaseException:
except BaseException: # noqa: B036
logger.error("Failed to close connection to " + connection_id)

def set_username(self, *args, **kwargs):
Expand Down Expand Up @@ -671,7 +671,7 @@ async def load_more_tracks(self, *args, **kwargs):
await self.get_spotify_token()
spotify_token = self.spotify_token
access_token = spotify_token["access_token"]
except BaseException:
except BaseException: # noqa: B036
error = "IrisFrontend: access_token missing or invalid"
logger.error(error)
return False
Expand Down Expand Up @@ -971,7 +971,7 @@ async def run_command(self, *args, **kwargs):
try:
http_client = AsyncHTTPClient()
command_response = await http_client.fetch(request)
except Exception as e:
except Exception as e: # noqa: B036
error = {"message": "Command failed", "description": str(e)}
if callback:
callback(False, error)
Expand All @@ -982,13 +982,13 @@ async def run_command(self, *args, **kwargs):
# Attempt to parse body as JSON
try:
command_response_body = json.loads(command_response.body)
except BaseException:
except BaseException: # noqa: B036
# Perhaps it requires unicode encoding?
try:
command_response_body = tornado.escape.to_unicode(
command_response.body
)
except BaseException:
except BaseException: # noqa: B036
command_response_body = ""

# Finally, return the result
Expand Down Expand Up @@ -1038,7 +1038,7 @@ async def refresh_spotify_token(self, *args, **kwargs):
"client_secret": self.config["spotify"]["client_secret"],
"grant_type": "client_credentials",
}
except (Exception):
except BaseException: # noqa: B036
error = {
"message": "Could not refresh Spotify token: invalid configuration"
}
Expand Down Expand Up @@ -1111,7 +1111,7 @@ async def get_lyrics(self, *args, **kwargs):
try:
path = request.get_argument("path")
url = "https://genius.com" + path
except Exception as e:
except Exception as e: # noqa: B036
logger.error(e)
error = {"message": "Path not valid", "description": str(e)}

Expand All @@ -1126,7 +1126,7 @@ async def get_lyrics(self, *args, **kwargs):
+ " not connected",
}

except Exception as e:
except Exception as e: # noqa: B036
logger.error(e)
error = {
"message": "Unauthorized request",
Expand Down Expand Up @@ -1206,7 +1206,7 @@ async def update_snapcast_meta(self, *args, **kwargs):
"message": "Could not update Snapcast meta",
error: error,
}
except Exception as e:
except Exception as e: # noqa: B036
logger.error(e)
response = {"message": "Could not update Snapcast meta"}

Expand Down
6 changes: 3 additions & 3 deletions mopidy_iris/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ async def on_message(self, message):
error=error,
),
)
except Exception as e:
except Exception as e: # noqa: B036
logger.error(str(e))

else:
Expand Down Expand Up @@ -222,7 +222,7 @@ async def get(self, slug=None):
id=id, method=slug, response=response, error=error
),
)
except Exception as e:
except Exception as e: # noqa: B036
logger.error(str(e))

else:
Expand All @@ -241,7 +241,7 @@ async def post(self, slug=None):

try:
params = json.loads(self.request.body.decode("utf-8"))
except BaseException:
except BaseException: # noqa: B036
self.handle_result(
id=id,
error={"code": 32700, "message": "Missing or invalid payload"},
Expand Down

0 comments on commit 7718bd2

Please sign in to comment.