subframe7536/maple-font · error · ValueError

line_height object must contain 'ascender' and 'descender' f

Error message

line_height object must contain 'ascender' and 'descender' fields

What it means

polish() accepts line_height either as a dict (requiring 'ascender' and 'descender' keys), a two-element list [ascender, descender], or a number (scale factor). If line_height is a dict (truthy, with more than just a 'factor' path) but lacks both 'ascender' and 'descender' fields, this ValueError is raised.

Source

Thrown at source/py/task/merge_font/utils.py:343

            change_line_height(font, line_height_config)
        elif isinstance(line_height_config, dict):
            # Object with ascender/descender and optional safe metrics
            ascender = line_height_config.get("top")
            descender = line_height_config.get("bottom")
            safe_ascender = line_height_config.get("safe_top")
            safe_descender = line_height_config.get("safe_bottom")

            if ascender is not None and descender is not None:
                change_line_height(
                    font,
                    1,
                    (ascender, descender),
                    (safe_ascender, safe_descender)
                    if safe_ascender is not None and safe_descender is not None
                    else None,
                )
            else:
                raise ValueError(
                    "line_height object must contain 'ascender' and 'descender' fields"
                )
        elif isinstance(line_height_config, list) and len(line_height_config) == 2:
            # Custom [ascender, descender] values
            change_line_height(
                font,
                1,
                (line_height_config[0], line_height_config[1]),
                (line_height_config[0], line_height_config[1]),
            )

    auto_xheight_capheight(font)

    postscript_name = f"{family_name.replace(' ', '')}-{style_name}"
    style_with_prefix_space, style_in_2, style_in_17, is_skip_subfamily, is_italic = (
        parse_style_name(
            style_name_compact=style_name,
        )

View on GitHub (pinned to c08fda97fe)

Solutions

  1. Provide both 'ascender' and 'descender' in the line_height object, or drop to the simple form: line_height: 1.2 (factor) or line_height: [ascender, descender].
  2. Check key spelling and case in the config (exactly 'ascender' and 'descender').
  3. If using a factor, ensure it is parsed as the numeric factor branch, not left as a dict with unrelated keys.

Example fix

# before
line_height:
  ascender: 1000   # descender missing

# after
line_height:
  ascender: 1000
  descender: -300
Defensive patterns

Strategy: validation

Validate before calling

lh = cfg.get("line_height")
if isinstance(lh, dict):
    assert "ascender" in lh and "descender" in lh, "line_height dict needs both ascender and descender"

Type guard

def is_valid_line_height(lh) -> bool:
    if isinstance(lh, (int, float)):
        return True
    if isinstance(lh, list) and len(lh) == 2:
        return True
    return isinstance(lh, dict) and "ascender" in lh and "descender" in lh

Try / catch

try:
    polish(font, config)
except ValueError as e:
    if "line_height" in str(e):
        print("Fix line_height: use factor, [ascender, descender], or {ascender, descender}")
    else:
        raise

Prevention

When it happens

Trigger: Config line_height given as an object like {factor: 1.2, typo: true} or {ascender: 1000} (descender missing), or misspelled keys ('Ascender', 'ascent'), reaching the else branch of the dict handling in polish().

Common situations: Config typos; YAML/JSON object intended as custom metrics but with one field forgotten; mixing the object form with the factor form incorrectly; schema drift after a config format change.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of subframe7536/maple-font@c08fda97fe (2026-08-28). Data as JSON: /api/errors/c23bba3e0c8819e6. Report an issue: GitHub.