Skip to content

Readability: Inconsistent error handling patterns across backends #32

@m96-chan

Description

@m96-chan

Summary

Error handling is inconsistent across different backends, making the code harder to understand and maintain.

Locations

Multiple files in src/proctap/backends/

Problem Examples

1. WindowsBackend - Swallows exceptions and returns empty bytes

# windows.py:124-128
if self._converter and data:
    try:
        data = self._converter.convert(data)
    except Exception as e:
        logger.error(f"Error converting audio format: {e}")
        return b''  # Silent failure

2. LinuxBackend - Swallows exceptions and returns empty bytes

# linux.py:1353-1358
if self._converter and data:
    try:
        data = self._converter.convert(data)
    except Exception as e:
        logger.error(f"Error converting audio format: {e}")
        return b''  # Silent failure

3. Core worker - Continues on exception

# core.py:218-222
try:
    data = self._backend.read()
except Exception:
    logger.exception("Error reading data from backend")
    continue  # Silently continues

4. PipeWireNative - Raises custom exceptions

# pipewire_native.py - Uses PipeWireError, PipeWireInitError, etc.
raise PipeWireStreamError(f"Failed to connect stream: {error_msg}")

Impact

  • Hard to distinguish between "no data available" and "error occurred"
  • Users cannot reliably detect and handle errors
  • Logging may be the only indication of issues

Suggested Fix

  1. Define consistent error handling strategy
  2. Consider raising exceptions for unrecoverable errors
  3. Return sentinel values (None vs b'') consistently:
    • None = no data available (normal)
    • b'' = empty data (normal)
    • Exception = actual error

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