ATH-MaaS/Pixelle-Video · error · ValueError

Failed to parse size from path: {template_path}. Expected fo

Error message

Failed to parse size from path: {template_path}. Expected format: 'WIDTHxHEIGHT/template.html' (e.g., '1080x1920/default.html'). Error: {e}

What it means

The int(width_str)/int(height_str) conversions and the bounds check inside parse_template_size run in a try block; any ValueError they raise is caught and re-raised as ValueError('Failed to parse size from path: ... Error: ...') with the original message appended. It means the directory name looked like WxH but the halves were not clean integers (or the bounds check tripped).

Source

Thrown at pixelle_video/utils/template_util.py:84

    # Parse size from directory name
    if 'x' not in dir_name:
        raise ValueError(
            f"Invalid size format in path: {template_path}. "
            f"Directory name should be 'WIDTHxHEIGHT' (e.g., '1080x1920')"
        )
    
    try:
        width_str, height_str = dir_name.split('x')
        width = int(width_str)
        height = int(height_str)
        
        # Sanity check
        if width < 100 or height < 100 or width > 10000 or height > 10000:
            raise ValueError(f"Invalid size dimensions: {width}x{height}")
        
        return (width, height)
    except ValueError as e:
        raise ValueError(
            f"Failed to parse size from path: {template_path}. "
            f"Expected format: 'WIDTHxHEIGHT/template.html' (e.g., '1080x1920/default.html'). "
            f"Error: {e}"
        )


def list_available_sizes() -> List[str]:
    """
    List all available video sizes (merged from templates/ and data/templates/)
    
    Returns:
        List of size strings like ["1080x1920", "1920x1080", "1080x1080"]
    
    Examples:
        >>> list_available_sizes()
        ['1080x1920', '1920x1080', '1080x1080']
    """
    # Use new resource API to merge default and custom directories

View on GitHub (pinned to 848b054e4f)

Solutions

  1. Rename the directory so both sides are plain integers: '1080x1920'.
  2. Strip unit suffixes/whitespace/separators from the directory name.
  3. Read the appended 'Error:' text to see the underlying cause (int parse failure vs dimension bounds).
  4. Normalize the path programmatically (regex ^\d+x\d+$) before calling the renderer.

Example fix

// before
templates/1080x1920px/default.html
// after
templates/1080x1920/default.html
Defensive patterns

Strategy: validation

Validate before calling

import re
from pathlib import Path

WxH_RE = re.compile(r"^(\d{3,5})x(\d{3,5})$")

def dir_parses_as_ints(template_path: str) -> bool:
    return bool(WxH_RE.fullmatch(Path(template_path).parent.name))

Type guard

def try_parse_size(template_path: str):
    m = WxH_RE.fullmatch(Path(template_path).parent.name)
    if not m:
        return None
    w, h = int(m.group(1)), int(m.group(2))
    return (w, h) if 100 <= w <= 10000 and 100 <= h <= 10000 else None

Try / catch

try:
    w, h = parse_template_size(template_path)
except ValueError as e:
    logger.error("Size parse failed for %s: %s", template_path, e)  # underlying cause in 'Error:' suffix
    raise

Prevention

When it happens

Trigger: Directory names like '1080x1920px', '10 80x1920', '1080x1_920', or '1080x' where int() fails on one side; also the bounds-check ValueError from entry 147 gets wrapped by this message.

Common situations: Units or suffixes in folder names ('1920pxx1080px'); thousands separators or underscores in dimensions; localized digit characters; accidentally doubling this error with 'Invalid size dimensions' when bounds fail.

Understand the failure class

Related errors


AI-assisted analysis of ATH-MaaS/Pixelle-Video@848b054e4f (2026-08-30). Data as JSON: /api/errors/788ed911af549bce. Report an issue: GitHub.