{"record":{"id":"5cde9f39668b7372","repo":"SubtitleEdit/subtitleedit","slug":"offset-is-empty","errorCode":null,"errorMessage":"Offset is empty.","messagePattern":"Offset is empty\\.","errorType":"exception","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"src/seconv/Core/OffsetParser.cs","lineNumber":17,"sourceCode":"using System.Globalization;\n\nnamespace SeConv.Core;\n\n/// <summary>\n/// Parses offset strings in the legacy Subtitle Edit CLI format. Accepts\n/// a plain integer (milliseconds) or colon/comma/period separated integer\n/// tokens treated as (hh, mm, ss, ms) — 4 tokens = hh:mm:ss:ms,\n/// 3 = mm:ss:ms, 2 = ss:ms, 1 = ms. Optional leading +/- repeated.\n/// </summary>\ninternal static class OffsetParser\n{\n    public static TimeSpan Parse(string input)\n    {\n        if (string.IsNullOrWhiteSpace(input))\n        {\n            throw new FormatException(\"Offset is empty.\");\n        }\n\n        var s = input.Trim();\n        var negate = false;\n        while (s.Length > 0 && (s[0] == '-' || s[0] == '+'))\n        {\n            if (s[0] == '-')\n            {\n                negate = !negate;\n            }\n            s = s[1..];\n        }\n\n        if (s.Length == 0)\n        {\n            throw Bad(input);\n        }\n","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/SubtitleEdit/subtitleedit/blob/17a9f0748781032255db3526b7215d2fb891e3af/src/seconv/Core/OffsetParser.cs#L1-L35","documentation":"Thrown by OffsetParser.Parse when the `--offset` value is null, empty, or whitespace. OffsetParser converts the legacy Subtitle Edit offset syntax (ms, ss:ms, mm:ss:ms, hh:mm:ss:ms) into a TimeSpan; an empty string has no parseable tokens, so it fails fast with FormatException.","triggerScenarios":"Calling `OffsetParser.Parse(input)` with an empty/whitespace string, typically because `--offset=` was passed with no value or the option was bound to an unset environment variable.","commonSituations":"Shell expansion that blanks the value (`--offset=$OFFSET` with OFFSET unset); a wrapper script passing an empty default; quoting mistake that strips the argument.","solutions":["Provide a concrete offset value, e.g. `--offset=1000` (1 second) or `--offset=00:00:01,500`.","If no offset is wanted, omit the `--offset` flag entirely rather than passing an empty value.","Guard wrapper scripts: only emit `--offset=` when the variable is non-empty."],"exampleFix":"# before\nseconv in.srt out.srt --offset=\n# after\nseconv in.srt out.srt --offset=1000","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(rawOffset))\n    throw new ArgumentException(\"--offset requires a value (ms or hh:mm:ss:ms)\");\nvar ts = OffsetParser.Parse(rawOffset);","typeGuard":"static bool IsOffsetParsable(string? s)\n{\n    if (string.IsNullOrWhiteSpace(s)) return false;\n    try { OffsetParser.Parse(s); return true; } catch { return false; }\n}","tryCatchPattern":"try { var offset = OffsetParser.Parse(input); }\ncatch (FormatException ex) when (ex.Message == \"Offset is empty.\")\n{\n    // treat as no offset, or report and abort\n}","preventionTips":["Default --offset to null/absent rather than empty in wrapper scripts.","Trim and length-check the value before calling Parse.","Document the accepted token shapes in --help."],"tags":["cli","parsing","time","offset","configuration"],"backgroundTag":null,"analyzedSha":"17a9f0748781032255db3526b7215d2fb891e3af","analyzedAt":"2026-08-13T18:11:43.374Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}