{"record":{"id":"cbf1390dcc76955f","repo":"SubtitleEdit/subtitleedit","slug":"settings-file-is-empty-or-null-path","errorCode":null,"errorMessage":"Settings file is empty or null: {path}","messagePattern":"Settings file is empty or null: (.+?)","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"error","filePath":"src/seconv/Core/SeConvSettings.cs","lineNumber":51,"sourceCode":"\n    private static readonly JsonSerializerOptions JsonOptions = new()\n    {\n        PropertyNamingPolicy = JsonNamingPolicy.CamelCase,\n        PropertyNameCaseInsensitive = true,\n        ReadCommentHandling = JsonCommentHandling.Skip,\n        AllowTrailingCommas = true,\n    };\n\n    public static SeConvSettings Load(string path)\n    {\n        if (!File.Exists(path))\n        {\n            throw new FileNotFoundException($\"Settings file not found: {path}\", path);\n        }\n\n        using var stream = File.OpenRead(path);\n        return JsonSerializer.Deserialize<SeConvSettings>(stream, JsonOptions)\n            ?? throw new InvalidDataException($\"Settings file is empty or null: {path}\");\n    }\n\n    /// <summary>\n    /// Serializes a complete settings file populated with the current libse defaults —\n    /// every key seconv understands, with its correct (camelCase) name and default value.\n    /// Backs <c>seconv dump-settings</c>, which users redirect to a file as a starting point\n    /// (issue #11037): it teaches the schema, so no one has to guess that the key is\n    /// <c>removeIfAllUppercase</c> and not the GUI's <c>IsRemoveTextUppercaseLineOn</c>.\n    /// <para>Built by mirroring <see cref=\"Configuration.Settings\"/> (the same source\n    /// <see cref=\"ApplyBaseSections\"/> writes back into) and a fresh <see cref=\"ImageExportStyle\"/>,\n    /// so the output round-trips through <see cref=\"Load\"/> with zero unknown keys — the dump\n    /// can never drift from what the loader accepts.</para>\n    /// </summary>\n    public static string DumpDefaults()\n    {\n        var s = Configuration.Settings;\n        var g = s.General;\n        var hi = s.RemoveTextForHearingImpaired;","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/SubtitleEdit/subtitleedit/blob/17a9f0748781032255db3526b7215d2fb891e3af/src/seconv/Core/SeConvSettings.cs#L33-L69","documentation":"Thrown by SeConvSettings.Load when the file exists and opens but `JsonSerializer.Deserialize<SeConvSettings>` returns null. With System.Text.Json this happens for an empty file, a file containing only whitespace/comments that JsonCommentHandling.Skip reduces to nothing, or content that deserializes to a null reference (e.g. the literal token `null`). InvalidDataException signals a structurally-empty input distinct from a missing file.","triggerScenarios":"Calling `SeConvSettings.Load(path)` on a zero-byte file, a file of only whitespace, or a file whose top-level JSON value is `null`.","commonSituations":"An interrupted `dump-settings` redirect (e.g. disk full, Ctrl-C); a manually created empty placeholder; a settings file overwritten by a failed pipeline; a `null` literal left from editing.","solutions":["Regenerate the file: `seconv dump-settings > settings.json`.","Open the file and confirm it contains a JSON object with keys.","If editing by hand, start from the dump output so the schema is correct.","Check the file is not zero bytes: `ls -l settings.json` / `dir settings.json`."],"exampleFix":"# before: settings.json is 0 bytes\nseconv in.srt out.srt --settings=settings.json\n# after\nseconv dump-settings > settings.json\nseconv in.srt out.srt --settings=settings.json","handlingStrategy":"try-catch","validationCode":"var info = new FileInfo(path);\nif (!info.Exists || info.Length == 0)\n    throw new ArgumentException(\"Settings file is missing or empty: \" + path);","typeGuard":"static bool SettingsFileHasContent(string? p)\n{\n    if (string.IsNullOrWhiteSpace(p) || !File.Exists(p)) return false;\n    return new FileInfo(p).Length > 0;\n}","tryCatchPattern":"try { var s = SeConvSettings.Load(path); }\ncatch (InvalidDataException ex) when (ex.Message.Contains(\"empty or null\"))\n{\n    // regenerate via dump-settings and retry\n}","preventionTips":["Check file size > 0 before deserializing.","Use `seconv dump-settings` as the canonical source of a non-empty file.","Validate JSON well-formedness with a linter in CI."],"tags":["settings","json","data-validation","empty-file","configuration"],"backgroundTag":null,"analyzedSha":"17a9f0748781032255db3526b7215d2fb891e3af","analyzedAt":"2026-08-13T18:11:43.374Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}