SubtitleEdit/subtitleedit · error · InvalidOperationException
Parse error in event #{i + 1}: {ex.Message}
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.
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)
Solutions
- Read the embedded ex.Message in the thrown error to identify the specific field/operation that failed.
- Open the .clqtt file, jump to event #{i+1}, and fix the noted field (e.g. add a missing start/end/txt).
- Remove the broken event if it is non-essential, then re-import.
- 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
- Pre-scan events for missing start/end/txt fields.
- Reject truncated CLQTT files before import.
- Keep the producer and importer versions aligned.
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
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Unknown time format '{timeFormat}'
- Unknown type of event #{i + 1}: '{type}'
- Parse error in event #{i + 1} style: {ex.Message}
- Element 'events' not found.
- Invalid ASSA time code: {time}
AI-assisted analysis of SubtitleEdit/subtitleedit@17a9f07487 (2026-08-13).
Data as JSON: /api/errors/bfb3144a0ff1f7d3.
Report an issue: GitHub.