SubtitleEdit/subtitleedit · error · InvalidOperationException

Element 'events' not found.

Error message

Element 'events' not found.

What it means

Thrown by ClqttJson.LoadSubtitle when the root JSON does not contain an 'events' element (case-insensitive find via GetRootElements). Without events there is nothing to import, so the loader aborts. Note the early-return guard only checks for the literal string "events"; this throw is the stricter structural check after parsing.

Source

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

                            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

  1. Confirm the file is genuinely a CLQTT subtitle file and not another JSON format.
  2. Ensure the root object has an "events": [ ... ] array with at least one entry.
  3. Re-export from the source tool with content included.

Example fix

// before
{ "meta": { "timeFormat": "FRAMES" } }
// after
{ "meta": { "timeFormat": "FRAMES" }, "events": [ { "eventType": "TIMED_TEXT_EVENT", "start": 0, "end": 100, "txt": "Hi" } ] }
Defensive patterns

Strategy: validation

Validate before calling

// Confirm an events array exists at the root before importing
var rootElements = parser.GetRootElements(text);
var eventsElement = rootElements.FirstOrDefault(e => e.Name.Equals("events", StringComparison.OrdinalIgnoreCase));
if (eventsElement == null)
{
    Console.WriteLine("No events array; nothing to import.");
    return;
}

Try / catch

try
{
    new ClqttJson().LoadSubtitle(sub, lines, fileName);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("Element 'events' not found"))
{
    logger.Warning("CLQTT file has no events; skipping.");
}

Prevention

When it happens

Trigger: A .clqtt file whose JSON root has meta but no events array, an empty events object, or a file whose events key is nested at the wrong level. Also a non-CLQTT JSON file that happens to contain the substring "events" and passes the initial guard.

Common situations: Truncated or stub CLQTT files; metadata-only exports; files misidentified as CLQTT by the auto-detector.

Related errors


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