Skip to content

Readability: Bare except clauses hide errors #36

@m96-chan

Description

@m96-chan

Summary

Several places in the code use bare except clauses (except: or except Exception:) which catch all exceptions and make debugging difficult.

Locations

linux.py - Multiple bare except blocks

# line 350-351
except:
    pass

# line 471-472
except:
    pass

# line 841-842
except:
    pass

pipewire_native.py

# line 1064
except:
    pass

# line 1375-1376
except:
    pass

linux.py LinuxBackend.del

# line 1386-1391
def __del__(self) -> None:
    """Destructor to ensure cleanup."""
    try:
        self.close()
    except:
        pass

Impact

  • Exceptions are silently swallowed
  • Makes debugging difficult
  • May hide actual bugs
  • Violates PEP 8 ("Bare except is equivalent to except BaseException")

Suggested Fix

  1. At minimum, log the exception:
except Exception as e:
    logger.debug(f"Cleanup failed (non-critical): {e}")
  1. Or catch specific exception types:
except (OSError, RuntimeError):
    pass  # Expected during cleanup
  1. For del methods, at least catch and ignore Exception (not BaseException):
except Exception:
    pass  # Suppress cleanup errors in destructor

Labels

readability, enhancement

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions