SubtitleEdit/subtitleedit · error · FormatException

PAC code page '{input}' is invalid. Expected a name (Latin,

Error message

PAC code page '{input}' is invalid. Expected a name (Latin, Greek, ...) or a number 0-12.

What it means

Thrown by PacCodepageParser.Parse when the input is non-empty but matches no named code page (Latin, Greek, Arabic, Hebrew, Cyrillic, Thai, Korean, Japanese, LatinTurkish/Turkish, LatinPortuguese/Portuguese) and is not an integer in the valid range 0..12 (Pac.CodePageLatin..Pac.CodePageLatinPortuguese). FormatException because the value is syntactically present but semantically invalid.

Source

Thrown at src/seconv/Core/PacCodepageParser.cs:51

    {
        if (string.IsNullOrWhiteSpace(input))
        {
            throw new FormatException("PAC code page is empty.");
        }

        var s = input.Trim();
        if (Named.TryGetValue(s, out var named))
        {
            return named;
        }

        if (int.TryParse(s, NumberStyles.None, CultureInfo.InvariantCulture, out var num) &&
            num >= Pac.CodePageLatin && num <= Pac.CodePageLatinPortuguese)
        {
            return num;
        }

        throw new FormatException(
            $"PAC code page '{input}' is invalid. Expected a name (Latin, Greek, ...) or a number 0-12.");
    }
}

View on GitHub (pinned to 17a9f07487)

Solutions

  1. Use one of the recognized names: Latin, Greek, Arabic, Hebrew, Cyrillic, Thai, Korean, Japanese, LatinTurkish, Turkish, LatinPortuguese, Portuguese.
  2. Use a numeric code 0-12 if you know the PAC ordinal.
  3. Do not pass Windows ANSI code page numbers (e.g. 1252) — these are not PAC codes.
  4. Check the exact spelling and case (matching is case-insensitive but exact-string).

Example fix

# before
seconv in.pac out.srt --pac-codepage=1252
# after
seconv in.pac out.srt --pac-codepage=Latin
Defensive patterns

Strategy: validation

Validate before calling

static readonly HashSet<string> PacNames = new(StringComparer.OrdinalIgnoreCase)
{ "Latin","Greek","Arabic","Hebrew","Cyrillic","Thai","Korean","Japanese","LatinTurkish","Turkish","LatinPortuguese","Portuguese" };
if (!PacNames.Contains(input) && !(int.TryParse(input, out var n) && n is >= 0 and <= 12))
    throw new ArgumentException("Invalid PAC code page: " + input);

Type guard

static bool IsValidPacCodepage(string? s) =>
    PacNames.Contains(s ?? "") || (int.TryParse(s, out var n) && n is >= 0 and <= 12);

Try / catch

try { var cp = PacCodepageParser.Parse(input); }
catch (FormatException ex) when (ex.Message.Contains("is invalid"))
{
    // print valid names, reprompt
}

Prevention

When it happens

Trigger: Calling `PacCodepageParser.Parse(input)` with a typo'd name (e.g. 'Latn', 'latin ' with trailing space handled, but 'Latian' not), or a number outside 0-12 (e.g. 13, -1, or a float like 1.5).

Common situations: Misspelling a code page name; passing a Windows code page number (1252, 932) instead of the PAC ordinal; version mismatch where a name was added/removed.

Related errors


AI-assisted analysis of SubtitleEdit/subtitleedit@17a9f07487 (2026-08-13). Data as JSON: /api/errors/675400730db44d18. Report an issue: GitHub.