spectreconsole/spectre.console · error · InvalidOperationException

Invalid Figlet font header signature

Error message

Invalid Figlet font header signature

What it means

Thrown by ParseHeader when the first token of the header fails the IsValidSignature check. A valid FIGlet signature begins with 'flf2' followed by a single character and the hardblank (e.g. 'flf2a$'). Any deviation causes this error.

Source

Thrown at src/Spectre.Console/Widgets/Figlet/FigletFontParser.cs:112

        return int.TryParse(index, style, CultureInfo.InvariantCulture, out result);
    }

    private static FigletHeader ParseHeader(string text)
    {
        if (string.IsNullOrWhiteSpace(text))
        {
            throw new InvalidOperationException("Invalid Figlet font");
        }

        var parts = text.SplitWords(StringSplitOptions.RemoveEmptyEntries);
        if (parts.Length < 6)
        {
            throw new InvalidOperationException("Invalid Figlet font header");
        }

        if (!IsValidSignature(parts[0]))
        {
            throw new InvalidOperationException("Invalid Figlet font header signature");
        }

        int? fullLayout = null;
        if (parts.Length > 7 && int.TryParse(parts[7], NumberStyles.Integer, CultureInfo.InvariantCulture, out var fl))
        {
            fullLayout = fl;
        }

        return new FigletHeader
        {
            Hardblank = parts[0][5],
            Height = int.Parse(parts[1], CultureInfo.InvariantCulture),
            Baseline = int.Parse(parts[2], CultureInfo.InvariantCulture),
            MaxLength = int.Parse(parts[3], CultureInfo.InvariantCulture),
            OldLayout = int.Parse(parts[4], CultureInfo.InvariantCulture),
            CommentLines = int.Parse(parts[5], CultureInfo.InvariantCulture),
            FullLayout = fullLayout,
        };

View on GitHub (pinned to 0acc92fada)

Solutions

  1. Confirm the file is genuinely a FIGlet (flf) font by checking the first token starts with 'flf2'.
  2. Re-download the font from the official FIGlet font archive.
  3. Validate the signature programmatically before loading.

Example fix

// before
var font = FigletFont.Load(File.ReadAllText("not-a-font.txt"));

// after
var content = File.ReadAllText("standard.flf");
if (!content.StartsWith("flf2")) throw new InvalidOperationException("Not a FIGlet font");
var font = FigletFont.Load(content);
Defensive patterns

Strategy: validation

Validate before calling

var signature = source.SplitLines().FirstOrDefault()?.SplitWords(StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();
if (signature == null || !signature.StartsWith("flf2")) throw new ArgumentException("Not a valid FIGlet font signature");

Type guard

static bool HasValidFigletSignature(string source)
{
    var sig = source.SplitLines().FirstOrDefault()?.SplitWords(StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();
    return sig != null && sig.StartsWith("flf2");
}

Prevention

When it happens

Trigger: Loading a file that is not a FIGlet font at all, or a FIGlet font with a corrupted/edited magic-number signature in its first token.

Common situations: Pointing the loader at a plain text file, a Terrafig or other format, or a font whose header was manually altered breaking the flf2 signature.

Related errors


AI-assisted analysis of spectreconsole/spectre.console@0acc92fada (2026-08-13). Data as JSON: /api/errors/bf17e858b3c11e69. Report an issue: GitHub.