from typing import Any
from typing import Optional


def format_strinfo_error(error: Any, filename: Optional[str] = None) -> str:
    """Format a strinfo error as a string."""
    # srcinfo is on major version 0 and the error format is ad-hoc and undocumented so
    # this is flexible in case the format changes.
    # Current format: {'line': Int, 'error': [Str]}
    # with only a single error message in the error list.
    filename_prefix = "" if filename is None else f"{filename}:"

    try:
        line = error["line"]
        messages = error["error"]
    except KeyError:
        return filename_prefix + str(error)

    if isinstance(messages, str):
        message = messages
    else:
        try:
            message = "; ".join(messages)
        except TypeError:
            message = str(messages)

    return f"{filename_prefix}{line}: {message}"