SubtitleEdit/subtitleedit · error · InvalidOperationException
Error in paragraph {p.StartTime} after '{sb}': {ex.Message}
Error message
Error in paragraph {p.StartTime} after '{sb}': {ex.Message} What it means
Thrown by Pac when decoding a PAC subtitle paragraph and an InvalidOperationException bubbles up from the inner decoding logic (alignment computation, margin calculation, or text processing). The wrapper enriches the message with the paragraph's StartTime and a prefix buffer 'sb' so the binary region that triggered the failure can be located.
Source
Thrown at src/libse/SubtitleFormats/Pac.cs:2010
}
var linesAfter = 12 - verticalAlignment - Math.Max(1, Utilities.GetNumberOfLines(p.Text));
p.MarginV = linesAfter <= 0 ? null : (linesAfter * 100 / 12.0).ToString(CultureInfo.InvariantCulture) + "%";
}
// Remove position tags
var indexOfPositioningCodes = p.Text.IndexOf("\u002e\u001f", StringComparison.Ordinal);
if (indexOfPositioningCodes > 0)
{
p.Text = p.Text.Substring(0, indexOfPositioningCodes + 1);
}
p.Text = p.Text.RemoveControlCharactersButWhiteSpace().TrimEnd();
return p;
}
catch (InvalidOperationException ex)
{
throw new InvalidOperationException($"Error in paragraph {p.StartTime} after '{sb}': {ex.Message}", ex);
}
}
/// <summary>
/// Fix italic tags, lines starting with ">" - whole line is italic, words between <> is italic
/// </summary>
private static string FixItalics(string input)
{
var pre = string.Empty;
var text = input;
if (text.StartsWith("{\\", StringComparison.Ordinal))
{
var endIdx = text.IndexOf('}', 2);
if (endIdx > 2)
{
pre = text.Substring(0, endIdx + 1);
text = text.Remove(0, endIdx + 1);
}View on GitHub (pinned to 17a9f07487)
Solutions
- Note the StartTime and 'sb' prefix in the message to locate the byte region in the file.
- Try the file in SubtitleEdit's GUI with the correct codepage/language selection.
- Re-acquire the PAC file from the original source — corruption is the most common cause.
- If decoding programmatically, catch the exception and skip the paragraph to salvage the rest.
Defensive patterns
Strategy: try-catch
Validate before calling
// Pac decoding is binary; best pre-check is file integrity
var fi = new FileInfo(fileName);
if (!fi.Exists || fi.Length < MinimumPacSize)
{
// reject obviously corrupt/empty files
return;
} Try / catch
try
{
new Pac().LoadSubtitle(sub, lines, fileName);
}
catch (InvalidOperationException ex) when (ex.Message.StartsWith("Error in paragraph"))
{
// ex.Message includes StartTime and a byte prefix to locate the region
logger.Error(ex, "PAC decode failed");
} Prevention
- Verify PAC files are not truncated before decoding.
- Select the correct language/codepage for the file.
- Catch per-paragraph to salvage the rest of the file where possible.
When it happens
Trigger: Decoding a PAC (.pac) file where the binary glyph/alignment data leads to an unexpected state during paragraph reconstruction — e.g. an out-of-range vertical alignment value, a missing encoding mapping, or malformed control codes that cause a substring or index operation to throw.
Common situations: Corrupt or non-standard PAC files; PAC files in a language/encoding the decoder does not fully map; files truncated before the paragraph terminator.
Related errors
- Unknown byte ({buffer[index]}) in subtitle file @ binary off
- Unknown byte ({b}) in subtitle file @ binary offset {index}.
- Unknown byte (0x{b:X2}) in subtitle file @ binary offset {in
- Parse error in event #{i + 1} style: {ex.Message}
- Invalid ASSA time code: {time}
AI-assisted analysis of SubtitleEdit/subtitleedit@17a9f07487 (2026-08-13).
Data as JSON: /api/errors/946ba4cdd006da37.
Report an issue: GitHub.