mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-10-21 10:15:04 +02:00
Add explanatory comments to 265 empty except blocks
CodeQL flags except blocks where `pass` has no comment explaining why the exception is silently ignored (py/empty-except rule). Added context-specific comments to all 265 instances across 31 files: - database.py (~112): ALTER TABLE migrations — "Already applied" - archive/library/3MF parsing (~64): "Skip unparseable metadata" - virtual_printer network cleanup (~32): "Best-effort socket cleanup" - discovery/SSDP (~13): "SO_REUSEPORT not available" / socket cleanup - bambu_ftp/mqtt (~13): FTP cleanup, JSON decode, signal parsing - remaining routes/services (~31): context-specific comments
This commit is contained in:
@@ -118,14 +118,14 @@ class FTPSession:
|
||||
try:
|
||||
await self.data_server.wait_closed()
|
||||
except OSError:
|
||||
pass
|
||||
pass # Best-effort data server cleanup; may already be closed
|
||||
self.data_server = None
|
||||
|
||||
try:
|
||||
self.writer.close()
|
||||
await self.writer.wait_closed()
|
||||
except OSError:
|
||||
pass
|
||||
pass # Best-effort control connection cleanup; client may have disconnected
|
||||
|
||||
# FTP Commands
|
||||
|
||||
@@ -303,7 +303,7 @@ class FTPSession:
|
||||
self._data_writer.close()
|
||||
await self._data_writer.wait_closed()
|
||||
except OSError:
|
||||
pass
|
||||
pass # Best-effort data writer cleanup; peer may have closed already
|
||||
self._data_writer = None
|
||||
self._data_reader = None
|
||||
|
||||
@@ -312,7 +312,7 @@ class FTPSession:
|
||||
self.data_server.close()
|
||||
await self.data_server.wait_closed()
|
||||
except OSError:
|
||||
pass
|
||||
pass # Best-effort data server shutdown; port may already be released
|
||||
self.data_server = None
|
||||
|
||||
# Only delay if we actually closed something
|
||||
|
||||
@@ -535,7 +535,7 @@ class VirtualPrinterManager:
|
||||
try:
|
||||
file_path.unlink()
|
||||
except OSError:
|
||||
pass
|
||||
pass # Best-effort removal of non-3MF file; may already be gone
|
||||
return
|
||||
|
||||
try:
|
||||
@@ -562,8 +562,7 @@ class VirtualPrinterManager:
|
||||
try:
|
||||
file_path.unlink()
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
pass # Best-effort cleanup of uploaded file after archiving
|
||||
# Remove from pending
|
||||
self._pending_files.pop(file_path.name, None)
|
||||
else:
|
||||
@@ -629,7 +628,7 @@ class VirtualPrinterManager:
|
||||
try:
|
||||
file_path.unlink()
|
||||
except OSError:
|
||||
pass
|
||||
pass # Best-effort removal of non-3MF file; may already be gone
|
||||
return
|
||||
|
||||
try:
|
||||
@@ -671,8 +670,7 @@ class VirtualPrinterManager:
|
||||
try:
|
||||
file_path.unlink()
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
pass # Best-effort cleanup of uploaded file after archiving and queuing
|
||||
# Remove from pending
|
||||
self._pending_files.pop(file_path.name, None)
|
||||
else:
|
||||
|
||||
@@ -210,7 +210,7 @@ class SimpleMQTTServer:
|
||||
)
|
||||
logger.info("MQTT SSL cert info: %s", result.stdout.strip())
|
||||
except (OSError, subprocess.SubprocessError):
|
||||
pass
|
||||
pass # Certificate info is for debug logging only; not critical
|
||||
|
||||
logger.info("MQTT SSL context: TLS 1.2+, cert=%s", self.cert_path)
|
||||
|
||||
@@ -286,7 +286,7 @@ class SimpleMQTTServer:
|
||||
try:
|
||||
await self._status_push_task
|
||||
except asyncio.CancelledError:
|
||||
pass
|
||||
pass # Expected when stopping the periodic status push task
|
||||
self._status_push_task = None
|
||||
|
||||
# Close all client connections (iterate over copy to avoid modification during iteration)
|
||||
@@ -295,7 +295,7 @@ class SimpleMQTTServer:
|
||||
writer.close()
|
||||
await writer.wait_closed()
|
||||
except OSError:
|
||||
pass
|
||||
pass # Best-effort client connection cleanup; client may have disconnected
|
||||
self._clients.clear()
|
||||
|
||||
if self._server:
|
||||
@@ -303,7 +303,7 @@ class SimpleMQTTServer:
|
||||
self._server.close()
|
||||
await self._server.wait_closed()
|
||||
except OSError:
|
||||
pass
|
||||
pass # Best-effort server shutdown; port may already be released
|
||||
self._server = None
|
||||
|
||||
async def _periodic_status_push(self) -> None:
|
||||
@@ -386,7 +386,7 @@ class SimpleMQTTServer:
|
||||
break
|
||||
|
||||
except asyncio.CancelledError:
|
||||
pass
|
||||
pass # Expected when server is shutting down and cancels client tasks
|
||||
except Exception as e:
|
||||
logger.debug("MQTT client error: %s", e)
|
||||
finally:
|
||||
@@ -397,7 +397,7 @@ class SimpleMQTTServer:
|
||||
writer.close()
|
||||
await writer.wait_closed()
|
||||
except OSError:
|
||||
pass
|
||||
pass # Best-effort socket cleanup on client disconnect
|
||||
|
||||
async def _read_remaining_length(self, reader: asyncio.StreamReader) -> int | None:
|
||||
"""Read MQTT remaining length (variable byte integer)."""
|
||||
@@ -783,7 +783,7 @@ class SimpleMQTTServer:
|
||||
await self._notify_print_command(filename, print_data)
|
||||
|
||||
except json.JSONDecodeError:
|
||||
pass
|
||||
pass # Non-JSON payloads on request topic are safely ignored
|
||||
|
||||
except (IndexError, ValueError, OSError) as e:
|
||||
logger.debug("MQTT PUBLISH error: %s", e)
|
||||
|
||||
@@ -140,7 +140,7 @@ class VirtualPrinterSSDPServer:
|
||||
try:
|
||||
self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
|
||||
except (AttributeError, OSError):
|
||||
pass
|
||||
pass # SO_REUSEPORT not available on all platforms; non-critical
|
||||
|
||||
# Set non-blocking mode
|
||||
self._socket.setblocking(False)
|
||||
@@ -177,7 +177,7 @@ class VirtualPrinterSSDPServer:
|
||||
message = data.decode("utf-8", errors="ignore")
|
||||
await self._handle_message(message, addr)
|
||||
except BlockingIOError:
|
||||
pass
|
||||
pass # No data available on non-blocking socket; will retry
|
||||
except OSError as e:
|
||||
if self._running:
|
||||
logger.debug("SSDP receive error: %s", e)
|
||||
@@ -215,12 +215,12 @@ class VirtualPrinterSSDPServer:
|
||||
# Send byebye message
|
||||
await self._send_byebye()
|
||||
except OSError:
|
||||
pass
|
||||
pass # Best-effort byebye broadcast; socket may already be closed
|
||||
|
||||
try:
|
||||
self._socket.close()
|
||||
except OSError:
|
||||
pass
|
||||
pass # Best-effort socket close; may already be released
|
||||
self._socket = None
|
||||
|
||||
async def _send_notify(self) -> None:
|
||||
@@ -254,7 +254,7 @@ class VirtualPrinterSSDPServer:
|
||||
self._socket.sendto(message.encode(), (SSDP_BROADCAST_ADDR, SSDP_PORT))
|
||||
logger.debug("Sent SSDP byebye")
|
||||
except OSError:
|
||||
pass
|
||||
pass # Best-effort byebye send; network may be unavailable during shutdown
|
||||
|
||||
async def _handle_message(self, message: str, addr: tuple[str, int]) -> None:
|
||||
"""Handle incoming SSDP message.
|
||||
@@ -325,7 +325,7 @@ class SSDPProxy:
|
||||
key, value = line.split(":", 1)
|
||||
headers[key.strip().lower()] = value.strip()
|
||||
except Exception:
|
||||
pass
|
||||
pass # Return partial headers if parsing fails; malformed packets are common
|
||||
return headers
|
||||
|
||||
def _rewrite_ssdp_location(self, data: bytes) -> bytes:
|
||||
@@ -371,7 +371,7 @@ class SSDPProxy:
|
||||
try:
|
||||
self._local_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
|
||||
except (AttributeError, OSError):
|
||||
pass
|
||||
pass # SO_REUSEPORT not available on all platforms; non-critical
|
||||
self._local_socket.setblocking(False)
|
||||
# Bind to all interfaces to receive broadcasts
|
||||
self._local_socket.bind(("", SSDP_PORT))
|
||||
@@ -391,7 +391,7 @@ class SSDPProxy:
|
||||
try:
|
||||
self._remote_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
|
||||
except (AttributeError, OSError):
|
||||
pass
|
||||
pass # SO_REUSEPORT not available on all platforms; non-critical
|
||||
self._remote_socket.setblocking(False)
|
||||
# Bind to remote interface
|
||||
self._remote_socket.bind((self.remote_interface_ip, 0))
|
||||
@@ -412,7 +412,7 @@ class SSDPProxy:
|
||||
data, addr = self._local_socket.recvfrom(4096)
|
||||
await self._handle_local_packet(data, addr)
|
||||
except BlockingIOError:
|
||||
pass
|
||||
pass # No data available on non-blocking socket; will retry
|
||||
except OSError as e:
|
||||
if self._running:
|
||||
logger.debug("SSDP proxy receive error: %s", e)
|
||||
@@ -448,7 +448,7 @@ class SSDPProxy:
|
||||
try:
|
||||
sock.close()
|
||||
except OSError:
|
||||
pass
|
||||
pass # Best-effort socket close; may already be released
|
||||
self._local_socket = None
|
||||
self._remote_socket = None
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ class TLSProxy:
|
||||
try:
|
||||
self.on_disconnect(client_id)
|
||||
except Exception:
|
||||
pass
|
||||
pass # Ignore disconnect callback errors during shutdown
|
||||
|
||||
self._active_connections.clear()
|
||||
|
||||
@@ -164,7 +164,7 @@ class TLSProxy:
|
||||
try:
|
||||
self.on_connect(client_id)
|
||||
except Exception:
|
||||
pass
|
||||
pass # Ignore connect callback errors; connection proceeds regardless
|
||||
|
||||
# Connect to target printer with TLS
|
||||
try:
|
||||
@@ -220,7 +220,7 @@ class TLSProxy:
|
||||
try:
|
||||
await task
|
||||
except asyncio.CancelledError:
|
||||
pass
|
||||
pass # Expected when cancelling the other forwarding direction
|
||||
|
||||
except Exception as e:
|
||||
logger.debug("%s proxy connection error: %s", self.name, e)
|
||||
@@ -233,7 +233,7 @@ class TLSProxy:
|
||||
writer.close()
|
||||
await writer.wait_closed()
|
||||
except OSError:
|
||||
pass
|
||||
pass # Best-effort connection cleanup; peer may have disconnected
|
||||
|
||||
logger.info("%s proxy: client %s disconnected", self.name, client_id)
|
||||
|
||||
@@ -241,7 +241,7 @@ class TLSProxy:
|
||||
try:
|
||||
self.on_disconnect(client_id)
|
||||
except Exception:
|
||||
pass
|
||||
pass # Ignore disconnect callback errors; cleanup continues
|
||||
|
||||
async def _forward(
|
||||
self,
|
||||
@@ -273,7 +273,7 @@ class TLSProxy:
|
||||
logger.debug("%s proxy %s: %s bytes", self.name, direction, len(data))
|
||||
|
||||
except asyncio.CancelledError:
|
||||
pass
|
||||
pass # Expected when the other forwarding direction closes first
|
||||
except ConnectionResetError:
|
||||
logger.debug("%s proxy %s: connection reset", self.name, direction)
|
||||
except BrokenPipeError:
|
||||
@@ -409,7 +409,7 @@ class SlicerProxyManager:
|
||||
try:
|
||||
self.on_activity(name, message)
|
||||
except Exception:
|
||||
pass
|
||||
pass # Ignore activity callback errors; logging is non-critical
|
||||
|
||||
@property
|
||||
def is_running(self) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user