spectreconsole/spectre.console · error · InvalidOperationException
Could not read header line
Error message
Could not read header line
What it means
Thrown by FigletFontParser.Parse when the source string contains no lines at all (FirstOrDefault returns null). This indicates the FIGlet font source is completely empty rather than merely malformed. The parser expects at least one header line.
Source
Thrown at src/Spectre.Console/Widgets/Figlet/FigletFontParser.cs:12
namespace Spectre.Console;
internal static class FigletFontParser
{
public static FigletFont Parse(string source)
{
var lines = source.SplitLines();
var headerLine = lines.FirstOrDefault();
if (headerLine == null)
{
throw new InvalidOperationException("Could not read header line");
}
var header = ParseHeader(headerLine);
var index = 32;
var indexOverridden = false;
var hasOverriddenIndex = false;
var buffer = new List<string>();
var characters = new List<FigletCharacter>();
var accumulatedHeight = 0;
var eolMarker = ParseEndOfLineMarker(lines, header);
foreach (var line in lines.Skip(header.CommentLines + 1))
{
// This might be an index?
if (!line.EndsWith(eolMarker))
{View on GitHub (pinned to 0acc92fada)
Solutions
- Verify the font source string is non-empty before parsing.
- Check that the embedded resource or file path resolves to a real FIGlet font file.
- Load one of the built-in fonts (FigletFont.Default) as a fallback when the custom font source is empty.
Example fix
// before var font = FigletFont.Load(emptySource); // after var font = string.IsNullOrWhiteSpace(emptySource) ? FigletFont.Default : FigletFont.Load(emptySource);
Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(source)) throw new ArgumentException("Figlet font source is empty");
var font = FigletFontParser.Parse(source); Type guard
static bool IsValidFontSource(string source) => !string.IsNullOrWhiteSpace(source);
Try / catch
try { var font = FigletFont.Load(source); }
catch (InvalidOperationException) { font = FigletFont.Default; } Prevention
- Verify embedded resource names match the assembly manifest.
- Check file size is non-zero before reading font content.
When it happens
Trigger: Calling FigletFontParser.Parse (directly or via FigletFont.Load) with an empty string, or loading a font file that is empty or unreadable yielding an empty string.
Common situations: Embedded resource returns empty due to wrong resource name or manifest lookup, reading a font file that was truncated/corrupted to zero bytes, or a network/HTTP fetch returning an empty body.
Related errors
- Invalid Figlet font
- Invalid Figlet font header
- Invalid Figlet font header signature
- Must be > 1
- 'name' cannot be null or empty.
AI-assisted analysis of spectreconsole/spectre.console@0acc92fada (2026-08-13).
Data as JSON: /api/errors/81e296840dae5359.
Report an issue: GitHub.