ruvnet/RuView · error · ValueError

Unknown unwrapping method: {self.unwrapping_method}

Error message

Unknown unwrapping method: {self.unwrapping_method}

What it means

ValueError raised by the defensive else branch in PhaseSanitizer.unwrap_phase when self.unwrapping_method matches none of 'numpy'/'scipy'/'custom'. Under normal use this is unreachable because _validate_config rejects invalid methods at construction; it fires only when the attribute is mutated after __init__ or when validation was bypassed. The surrounding except immediately wraps it into PhaseSanitizationError, so callers see error 138's message carrying this text.

Source

Thrown at archive/v1/src/core/phase_sanitizer.py:97

        
        Args:
            phase_data: Wrapped phase data (2D array)
            
        Returns:
            Unwrapped phase data
            
        Raises:
            PhaseSanitizationError: If unwrapping fails
        """
        try:
            if self.unwrapping_method == 'numpy':
                return self._unwrap_numpy(phase_data)
            elif self.unwrapping_method == 'scipy':
                return self._unwrap_scipy(phase_data)
            elif self.unwrapping_method == 'custom':
                return self._unwrap_custom(phase_data)
            else:
                raise ValueError(f"Unknown unwrapping method: {self.unwrapping_method}")
                
        except Exception as e:
            raise PhaseSanitizationError(f"Failed to unwrap phase: {e}")
    
    def _unwrap_numpy(self, phase_data: np.ndarray) -> np.ndarray:
        """Unwrap phase using numpy's unwrap function."""
        if phase_data.size == 0:
            raise ValueError("Cannot unwrap empty phase data")
        return np.unwrap(phase_data, axis=1)
    
    def _unwrap_scipy(self, phase_data: np.ndarray) -> np.ndarray:
        """Unwrap phase using scipy's unwrap function."""
        if phase_data.size == 0:
            raise ValueError("Cannot unwrap empty phase data")
        return np.unwrap(phase_data, axis=1)
    
    def _unwrap_custom(self, phase_data: np.ndarray) -> np.ndarray:
        """Unwrap phase using custom algorithm."""

View on GitHub (pinned to 4685618388)

Solutions

  1. Never mutate unwrapping_method after construction; create a new PhaseSanitizer instance with the desired method: PhaseSanitizer({**old.config, 'unwrapping_method': 'scipy'}).
  2. If runtime switching is required, keep a dict of pre-built sanitizer instances per method and select among them.
  3. When restoring state from saved config, route through the constructor instead of setattr so _validate_config runs.
  4. In tests, patch via constructing with the method you need rather than overwriting the attribute.

Example fix

# before
sanitizer.unwrapping_method = 'scipy_v2'   # bypasses validation
unwrapped = sanitizer.unwrap_phase(phase)   # Unknown unwrapping method

# after
sanitizer = PhaseSanitizer({**sanitizer.config, 'unwrapping_method': 'scipy'})
unwrapped = sanitizer.unwrap_phase(phase)
Defensive patterns

Strategy: validation

Validate before calling

VALID_METHODS = ('numpy', 'scipy', 'custom')

def switch_method(sanitizer, method: str) -> 'PhaseSanitizer':
    if method not in VALID_METHODS:
        raise ValueError(f'{method!r} not in {VALID_METHODS}')
    return PhaseSanitizer({**sanitizer.config, 'unwrapping_method': method})

# sanitizer = switch_method(sanitizer, 'scipy')  # never mutate the attribute

Type guard

from typing import TypeGuard

VALID_METHODS = ('numpy', 'scipy', 'custom')

def is_valid_unwrap_method(value: object) -> TypeGuard[str]:
    return isinstance(value, str) and value in VALID_METHODS

Try / catch

try:
    unwrapped = sanitizer.unwrap_phase(phase_data)
except PhaseSanitizationError as e:
    if 'Unknown unwrapping method' in str(e):
        sanitizer = PhaseSanitizer(sanitizer.config)  # rebuild with validated config
        unwrapped = sanitizer.unwrap_phase(phase_data)
    else:
        raise

Prevention

When it happens

Trigger: Assigning sanitizer.unwrapping_method = 'scipy_unwrap' (or any non-whitelisted value) after construction and then calling unwrap_phase(phase_data). Also reachable in subclasses or tests that skip __init__ (e.g. PhaseSanitizer.__new__) and set attributes manually.

Common situations: Hot-swapping the method at runtime based on data characteristics without revalidating; monkeypatching in tests that writes an invalid method name; deserialization code that restores instance attributes from a saved config of a different version without running validation.

Related errors


AI-assisted analysis of ruvnet/RuView@4685618388 (2026-08-16). Data as JSON: /api/errors/a244f8b2ae6444e1. Report an issue: GitHub.