{"record":{"id":"3ef7aa53347da32f","repo":"SubtitleEdit/subtitleedit","slug":"subtitle-file-not-found-filepath","errorCode":null,"errorMessage":"Subtitle file not found: {filePath}","messagePattern":"Subtitle file not found: (.+?)","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"src/seconv/Core/LibSEIntegration.cs","lineNumber":65,"sourceCode":"        return entries;\n    }\n\n    public sealed record FormatEntry(SubtitleFormat Format, string Kind);\n\n    /// <summary>\n    /// Loads a subtitle file using LibSE. When <paramref name=\"encodingName\"/> is null/blank,\n    /// the encoding is auto-detected from the file's content. When\n    /// <paramref name=\"fallbackEncodingName\"/> is supplied (and <paramref name=\"encodingName\"/>\n    /// is not), the fallback replaces the ANSI codepage heuristic: a BOM still wins, valid\n    /// UTF-8 still wins, but anything else uses the fallback rather than DetectAnsiEncoding.\n    /// Also returns the detected source format so the save side can apply\n    /// <c>RemoveNativeFormatting</c> if the target is different.\n    /// </summary>\n    public static (Subtitle Subtitle, SubtitleFormat Format) LoadSubtitleWithFormat(string filePath, string? encodingName = null, string? fallbackEncodingName = null, List<string>? warnings = null)\n    {\n        if (!File.Exists(filePath))\n        {\n            throw new FileNotFoundException($\"Subtitle file not found: {filePath}\");\n        }\n\n        var subtitle = new Subtitle();\n        Encoding encoding;\n        if (!string.IsNullOrWhiteSpace(encodingName))\n        {\n            encoding = GetEncoding(encodingName);\n        }\n        else if (!string.IsNullOrWhiteSpace(fallbackEncodingName))\n        {\n            encoding = DetectEncodingWithFallback(filePath, fallbackEncodingName);\n        }\n        else\n        {\n            encoding = LanguageAutoDetect.GetEncodingFromFile(filePath);\n        }\n\n        var lines = new List<string>(File.ReadAllLines(filePath, encoding));","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/SubtitleEdit/subtitleedit/blob/17a9f0748781032255db3526b7215d2fb891e3af/src/seconv/Core/LibSEIntegration.cs#L47-L83","documentation":"Thrown by LoadSubtitleWithFormat when the subtitle file does not exist on disk (File.Exists returns false). This is the standard FileNotFoundException — the path is unresolvable, the file was deleted, or the path is wrong. The file path is embedded in the message for diagnostics.","triggerScenarios":"Calling LoadSubtitleWithFormat(filePath, ...) where filePath points to a non-existent file. Common in CLI invocations with a typo'd path, a relative path resolved from the wrong working directory, or a file that was moved/deleted between validation and load.","commonSituations":"Typo in the CLI input path; relative path resolved against an unexpected CWD (especially in scripts or batch jobs); file on a network mount that dropped; race between file creation and this call.","solutions":["Verify the path with File.Exists before calling LoadSubtitleWithFormat, and surface a clean error.","If the path is relative, resolve it against the intended base directory with Path.GetFullPath before the call.","Check for typos, trailing spaces, or shell-quoting issues in the argument."],"exampleFix":"// before\nvar (sub, fmt) = LibSEIntegration.LoadSubtitleWithFormat(path);\n\n// after\nif (!File.Exists(path))\n    throw new FileNotFoundException($\"Input subtitle not found: {path}\");\nvar (sub, fmt) = LibSEIntegration.LoadSubtitleWithFormat(path);","handlingStrategy":"validation","validationCode":"if (!File.Exists(filePath))\n    throw new FileNotFoundException($\"Subtitle file not found: {filePath}\", filePath);\nvar (sub, fmt) = LibSEIntegration.LoadSubtitleWithFormat(filePath);","typeGuard":"static bool IsSubtitleFileReadable(string path) => File.Exists(path);","tryCatchPattern":"try { var (sub, fmt) = LibSEIntegration.LoadSubtitleWithFormat(path); }\ncatch (FileNotFoundException ex) when (ex.Message.Contains(\"Subtitle file not found\"))\n{ /* report missing input file to user, check path/spelling */ }","preventionTips":["Validate File.Exists for every input path before calling load methods.","Resolve relative paths to absolute with Path.GetFullPath to surface CWD issues early.","In CLI tools, validate all input paths in an argument-parsing phase before any processing begins."],"tags":["file-not-found","validation","path","subtitles"],"backgroundTag":null,"analyzedSha":"17a9f0748781032255db3526b7215d2fb891e3af","analyzedAt":"2026-08-13T18:11:43.374Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}