{"record":{"id":"c0228c009b937173","repo":"SubtitleEdit/subtitleedit","slug":"failed-to-open-file-filepath","errorCode":null,"errorMessage":"Failed to open file: {filePath}","messagePattern":"Failed to open file: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/ui/Logic/Media/FileHelper.cs","lineNumber":769,"sourceCode":"                }\n                else if (OperatingSystem.IsLinux())\n                {\n                    // Linux: use 'xdg-open' command\n                    Process.Start(new ProcessStartInfo\n                    {\n                        FileName = \"xdg-open\",\n                        Arguments = $\"\\\"{filePath}\\\"\",\n                        UseShellExecute = false\n                    });\n                }\n                else\n                {\n                    throw new PlatformNotSupportedException(\"Unsupported operating system\");\n                }\n            }\n            catch (Exception ex) when (ex is not FileNotFoundException && ex is not ArgumentException)\n            {\n                throw new InvalidOperationException($\"Failed to open file: {filePath}\", ex);\n            }\n        }\n    }\n}\n","sourceCodeStart":751,"sourceCodeEnd":774,"githubUrl":"https://github.com/SubtitleEdit/subtitleedit/blob/17a9f0748781032255db3526b7215d2fb891e3af/src/ui/Logic/Media/FileHelper.cs#L751-L774","documentation":"Thrown by OpenFileWithDefaultProgram as a catch-all wrapper for any exception escaping the Process.Start calls that is not already FileNotFoundException or ArgumentException (those are explicitly filtered out by the when clause). The inner exception is preserved as InnerException. Typical inner causes: Win32Exception (ERROR_NO_ASSOCIATION / file not executable / access denied), the opener binary missing (xdg-open not installed), or permission errors.","triggerScenarios":"Process.Start throws inside the try: no application associated with the file extension on Windows, xdg-open/open missing on Linux/macOS, the file or opener is not executable, or a sandbox blocks the launch.","commonSituations":"A file type with no registered default app; a minimal Linux distro without xdg-open; macOS Gatekeeper blocking the opener; insufficient permissions to launch.","solutions":["Inspect InnerException (often a Win32Exception) for the native error code and message.","Register a default application for the file extension (Windows) or install xdg-open / open (Linux/macOS).","Ensure the file and the opener are executable and that the process has launch permissions.","Catch InvalidOperationException around the call and present InnerException.Message to the user with a 'choose app manually' option."],"exampleFix":"// before\nFileHelper.OpenFileWithDefaultProgram(path);\n\n// after\ncatch (InvalidOperationException ex) when (ex.InnerException is System.ComponentModel.Win32Exception we)\n{\n    if (we.NativeErrorCode == 1155 /*ERROR_NO_ASSOCIATION*/)\n        showOpenWithDialog(path); // let user pick an app\n    else\n        showUser(ex.InnerException.Message);\n}","handlingStrategy":"try-catch","validationCode":"if (!OperatingSystem.IsLinux() || File.Exists(\"/usr/bin/xdg-open\"))\n    FileHelper.OpenFileWithDefaultProgram(path);\nelse showUser(\"xdg-open is not installed\");","typeGuard":null,"tryCatchPattern":"try { FileHelper.OpenFileWithDefaultProgram(path); }\ncatch (InvalidOperationException ex) when (ex.InnerException is System.ComponentModel.Win32Exception we)\n{\n    if (we.NativeErrorCode == 1155 /*ERROR_NO_ASSOCIATION*/) ShowOpenWithDialog(path);\n    else showUser(we.Message);\n}","preventionTips":["Ensure a default application is registered for the file extension.","On Linux verify xdg-open is installed before relying on it.","Catch InvalidOperationException and inspect InnerException for the native error."],"tags":["process","filesystem","win32","permissions","default-program"],"backgroundTag":null,"analyzedSha":"17a9f0748781032255db3526b7215d2fb891e3af","analyzedAt":"2026-08-13T18:11:43.374Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}