SubtitleEdit/subtitleedit · error · InvalidOperationException

Parse error in event #

Error message

Parse error in event #{i + 1}: {ex.Message}

What it means

A catch-all wrapper thrown by ClqttJson.LoadSubtitle when any exception escapes the per-event try block (the outer event loop). The inner exception's message is prefixed with the 1-based event index, so the offending event can be located. It covers JSON field access, start/end frame parsing, region detection, and annotation handling that is not already caught by the inner style handler.

Solutions

  1. Read the embedded ex.Message in the thrown error to identify the specific field/operation that failed.
  2. Open the .clqtt file, jump to event #{i+1}, and fix the noted field (e.g. add a missing start/end/txt).
  3. Remove the broken event if it is non-essential, then re-import.
  4. Re-export the file from the source tool.
Defensive patterns

Strategy: try-catch

Validate before calling

// Validate required fields exist before importing
var start = parser.GetFirstObject(eventJson, "start");
var end = parser.GetFirstObject(eventJson, "end");
var txt = parser.GetFirstObject(eventJson, "txt");
if (string.IsNullOrEmpty(start) || string.IsNullOrEmpty(end) || string.IsNullOrEmpty(txt))
{
    // skip incomplete event
    continue;
}

Try / catch

try
{
    new ClqttJson().LoadSubtitle(sub, lines, fileName);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("Parse error in event"))
{
    // ex.Message embeds the 1-based event index and inner cause
    logger.Error(ex, "CLQTT event parse failed");
}

Prevention

When it happens

Trigger: Any unhandled exception while processing a single CLQTT event: a missing 'start'/'end'/'txt' field, a non-numeric frame value, a null annotation, or a JSON structure that deviates from expectations. The error message embeds ex.Message so the root cause is visible.

Common situations: A partially-valid CLQTT file where most events are fine but one is malformed; files truncated mid-stream; schema drift between producer and this importer.

Understand the failure class

Related errors


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

Appendix: source

Thrown at src/libse/SubtitleFormats/ClqttJson.cs:172

                            }

                            subText = subText.Replace("\r\n", Environment.NewLine).Replace("\n", Environment.NewLine);
                            subText = subTextPrefix + Json.DecodeJsonText(subText);

                            var p = new Paragraph(subText, FramesToMilliseconds(start, frameRate), FramesToMilliseconds(end, frameRate));
                            p.Region = region;

                            if (annotations.Count > 0)
                            {
                                p.Bookmark = String.Join(Environment.NewLine + Environment.NewLine, annotations);
                            }

                            subtitle.Paragraphs.Add(p);
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new InvalidOperationException($"Parse error in event #{i + 1}: {ex.Message}", ex);
                    }
                }
            }
            else
            {
                throw new InvalidOperationException($"Element 'events' not found.");
            }

            subtitle.Renumber();
        }
    }
}

View on GitHub (pinned to 17a9f07487)