{"record":{"id":"5983d2a78d09e1a8","repo":"SubtitleEdit/subtitleedit","slug":"resolution-is-empty","errorCode":null,"errorMessage":"Resolution is empty.","messagePattern":"Resolution is empty\\.","errorType":"validation","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"src/seconv/Core/ResolutionParser.cs","lineNumber":15,"sourceCode":"using System.Globalization;\n\nnamespace SeConv.Core;\n\n/// <summary>\n/// Parses <c>WIDTHxHEIGHT</c> strings (e.g. <c>1920x1080</c>) used by <c>--resolution</c>.\n/// Both lowercase <c>x</c> and uppercase <c>X</c> are accepted.\n/// </summary>\ninternal static class ResolutionParser\n{\n    public static (int Width, int Height) Parse(string input)\n    {\n        if (string.IsNullOrWhiteSpace(input))\n        {\n            throw new FormatException(\"Resolution is empty.\");\n        }\n\n        var s = input.Trim();\n        var idx = s.IndexOfAny(['x', 'X']);\n        if (idx <= 0 || idx == s.Length - 1)\n        {\n            throw new FormatException($\"Resolution '{input}' is invalid. Expected WIDTHxHEIGHT, e.g. 1920x1080.\");\n        }\n\n        var wPart = s[..idx];\n        var hPart = s[(idx + 1)..];\n\n        if (!int.TryParse(wPart, NumberStyles.None, CultureInfo.InvariantCulture, out var w) ||\n            !int.TryParse(hPart, NumberStyles.None, CultureInfo.InvariantCulture, out var h) ||\n            w <= 0 || h <= 0)\n        {\n            throw new FormatException($\"Resolution '{input}' is invalid. Width and height must be positive integers.\");\n        }","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/SubtitleEdit/subtitleedit/blob/17a9f0748781032255db3526b7215d2fb891e3af/src/seconv/Core/ResolutionParser.cs#L1-L33","documentation":"Thrown by ResolutionParser.Parse when the `--resolution` value is null/empty/whitespace. The parser splits a WIDTHxHEIGHT string (e.g. 1920x1080) into a tuple for bitmap rendering at the correct dimensions; an empty string has no separator or tokens.","triggerScenarios":"Calling `ResolutionParser.Parse(input)` with an empty/whitespace string, typically `--resolution=` with no value.","commonSituations":"Shell expansion blanking the variable; wrapper script defaulting to empty; user assumes a default resolution exists but bitmap export requires an explicit one.","solutions":["Pass a WIDTHxHEIGHT value, e.g. `--resolution=1920x1080`.","Omit `--resolution` entirely if your conversion does not need bitmap dimensions.","Guard scripts: only emit the flag when the variable is non-empty."],"exampleFix":"# before\nseconv in.sup out.bdnxml --resolution=\n# after\nseconv in.sup out.bdnxml --resolution=1920x1080","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(rawRes))\n    throw new ArgumentException(\"--resolution requires WIDTHxHEIGHT\");\nvar (w,h) = ResolutionParser.Parse(rawRes);","typeGuard":"static bool IsResolutionParsable(string? s)\n{\n    if (string.IsNullOrWhiteSpace(s)) return false;\n    try { ResolutionParser.Parse(s); return true; } catch { return false; }\n}","tryCatchPattern":"try { var res = ResolutionParser.Parse(input); }\ncatch (FormatException ex) when (ex.Message == \"Resolution is empty.\")\n{\n    // require resolution for bitmap targets, else skip\n}","preventionTips":["Make --resolution mandatory only for bitmap outputs (.sup, .bdnxml, ...).","Trim and length-check the value before parsing.","Document a default (e.g. 1920x1080) in --help."],"tags":["cli","parsing","resolution","configuration","bitmap"],"backgroundTag":null,"analyzedSha":"17a9f0748781032255db3526b7215d2fb891e3af","analyzedAt":"2026-08-13T18:11:43.374Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}