subframe7536/maple-font · error · ValueError

Invalid font source type: {type(source)}

Error message

Invalid font source type: {type(source)}

What it means

prepare_font_source() accepts only two kinds of font sources: a str path to a .ttf/.otf file, or a dict override config with a 'path' key. If `source` is any other Python type (int, list, None, a Path object, etc.) it falls through all isinstance checks and raises this ValueError in main.py:189. It is a defensive type check at the end of the function.

Source

Thrown at source/py/task/merge_font/__init__.py:189

            temp_path = joinPaths(tmp_dir, temp_filename)
            instantiate(font_path, temp_path, axes)
            print(f"  Instantiated: {temp_path}")
            font_path = temp_path
            result["is_temp"] = True
        else:
            # Static font - copy if non-ASCII path
            if is_ascii_path(font_path):
                result["path"] = font_path
            else:
                print(f"  Copying non-ASCII path font to tmp: {font_path}")
                result["path"] = copy_to_tmp_with_ascii_name(font_path, output_dir)
                result["is_temp"] = True
            return result

        result["path"] = font_path
        return result

    raise ValueError(f"Invalid font source type: {type(source)}")


def main(cleanup: bool = False):
    print("Font merge script (Multi-Font Support)")

    # Load and validate config
    config_data = load_config()
    validate_config(config_data)

    family_name = config_data["family_name"]
    output_dir = config_data["output_dir"]
    line_height_config = config_data.get("line_height")
    instances = config_data["instances"]

    # Create directories
    if not path.exists(output_dir):
        mkdir(output_dir)
        print(f"Created output directory: {output_dir}")

View on GitHub (pinned to c08fda97fe)

Solutions

  1. Fix the config so each font source is either a plain path string or an object with a 'path' field.
  2. If calling programmatically, convert pathlib.Path to str(source) before passing it.
  3. Check the printed type in the message to identify which entry has the wrong type, then inspect that config key.

Example fix

# before (config.yaml)
mainFont:
  # empty value -> None

# after (config.yaml)
mainFont:
  path: fonts/MyFont.ttf
Defensive patterns

Strategy: type-guard

Validate before calling

src = cfg["source"]
assert isinstance(src, (str, dict)), f"font source must be str path or dict, got {type(src)}"

Type guard

def is_valid_font_source(source) -> bool:
    return isinstance(source, str) or (isinstance(source, dict) and bool(source.get("path")))

Try / catch

try:
    prepare_font_source(source, ...)
except ValueError as e:
    if "Invalid font source type" in str(e):
        print(f"Fix config font entry: {e}")
        sys.exit(1)
    raise

Prevention

When it happens

Trigger: Calling main()/prepare_font_source with a font source entry in the config that is not a string and not a dict — e.g. source is None (YAML key present but empty), a list of paths, a pathlib.Path object, or a number.

Common situations: Config file mistakes: a font entry left empty in YAML/JSON (parses to None), accidentally nesting a font under a list, passing pathlib.Path instead of str when calling the function programmatically, or a schema change in the config format.

Related errors


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