{"record":{"id":"946ba4cdd006da37","repo":"SubtitleEdit/subtitleedit","slug":"error-in-paragraph-p-starttime-after-sb-ex","errorCode":null,"errorMessage":"Error in paragraph {p.StartTime} after '{sb}': {ex.Message}","messagePattern":"Error in paragraph (.+?) after '(.+?)': (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/libse/SubtitleFormats/Pac.cs","lineNumber":2010,"sourceCode":"                    }\n\n                    var linesAfter = 12 - verticalAlignment - Math.Max(1, Utilities.GetNumberOfLines(p.Text));\n                    p.MarginV = linesAfter <= 0 ? null : (linesAfter * 100 / 12.0).ToString(CultureInfo.InvariantCulture) + \"%\";\n                }\n\n                // Remove position tags\n                var indexOfPositioningCodes = p.Text.IndexOf(\"\\u002e\\u001f\", StringComparison.Ordinal);\n                if (indexOfPositioningCodes > 0)\n                {\n                    p.Text = p.Text.Substring(0, indexOfPositioningCodes + 1);\n                }\n\n                p.Text = p.Text.RemoveControlCharactersButWhiteSpace().TrimEnd();\n                return p;\n            }\n            catch (InvalidOperationException ex)\n            {\n                throw new InvalidOperationException($\"Error in paragraph {p.StartTime} after '{sb}': {ex.Message}\", ex);\n            }\n        }\n\n        /// <summary>\n        /// Fix italic tags, lines starting with \">\" - whole line is italic, words between &lt;&gt; is italic\n        /// </summary>\n        private static string FixItalics(string input)\n        {\n            var pre = string.Empty;\n            var text = input;\n            if (text.StartsWith(\"{\\\\\", StringComparison.Ordinal))\n            {\n                var endIdx = text.IndexOf('}', 2);\n                if (endIdx > 2)\n                {\n                    pre = text.Substring(0, endIdx + 1);\n                    text = text.Remove(0, endIdx + 1);\n                }","sourceCodeStart":1992,"sourceCodeEnd":2028,"githubUrl":"https://github.com/SubtitleEdit/subtitleedit/blob/17a9f0748781032255db3526b7215d2fb891e3af/src/libse/SubtitleFormats/Pac.cs#L1992-L2028","documentation":"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.","triggerScenarios":"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.","commonSituations":"Corrupt or non-standard PAC files; PAC files in a language/encoding the decoder does not fully map; files truncated before the paragraph terminator.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pac decoding is binary; best pre-check is file integrity\nvar fi = new FileInfo(fileName);\nif (!fi.Exists || fi.Length < MinimumPacSize)\n{\n    // reject obviously corrupt/empty files\n    return;\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    new Pac().LoadSubtitle(sub, lines, fileName);\n}\ncatch (InvalidOperationException ex) when (ex.Message.StartsWith(\"Error in paragraph\"))\n{\n    // ex.Message includes StartTime and a byte prefix to locate the region\n    logger.Error(ex, \"PAC decode failed\");\n}","preventionTips":["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."],"tags":["subtitle-format","pac","binary","decoding","index-out-of-range"],"backgroundTag":null,"analyzedSha":"17a9f0748781032255db3526b7215d2fb891e3af","analyzedAt":"2026-08-13T18:11:43.374Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}