{"record":{"id":"6ad66f5ce97a2bb7","repo":"Flow-Launcher/Flow.Launcher","slug":"failed-to-parse-folder-path","errorCode":null,"errorMessage":"Failed to parse folder path","messagePattern":"Failed to parse folder path","errorType":"exception","errorClass":"COMException","httpStatus":null,"severity":"warning","filePath":"Flow.Launcher.Infrastructure/Win32Helper.cs","lineNumber":871,"sourceCode":"        }\n\n        #endregion\n\n        #region Explorer\n\n        // https://learn.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shopenfolderandselectitems\n\n        public static unsafe void OpenFolderAndSelectFile(string filePath)\n        {\n            ITEMIDLIST* pidlFolder = null;\n            ITEMIDLIST* pidlFile = null;\n\n            var folderPath = Path.GetDirectoryName(filePath);\n\n            try\n            {\n                var hrFolder = PInvoke.SHParseDisplayName(folderPath, null, out pidlFolder, 0, out _);\n                if (hrFolder.Failed) throw new COMException(\"Failed to parse folder path\", hrFolder);\n\n                var hrFile = PInvoke.SHParseDisplayName(filePath, null, out pidlFile, 0, out _);\n                if (hrFile.Failed) throw new COMException(\"Failed to parse file path\", hrFile);\n\n                var hrSelect = PInvoke.SHOpenFolderAndSelectItems(pidlFolder, 1, &pidlFile, 0);\n                if (hrSelect.Failed) throw new COMException(\"Failed to open folder and select item\", hrSelect);\n            }\n            finally\n            {\n                if (pidlFile != null) PInvoke.CoTaskMemFree(pidlFile);\n                if (pidlFolder != null) PInvoke.CoTaskMemFree(pidlFolder);\n            }\n        }\n\n        #endregion\n\n        #region Win32 Dark Mode\n","sourceCodeStart":853,"sourceCodeEnd":889,"githubUrl":"https://github.com/Flow-Launcher/Flow.Launcher/blob/7fc63b07bbaa10a0f0b2601487913fcba9ed24b0/Flow.Launcher.Infrastructure/Win32Helper.cs#L853-L889","documentation":"Thrown as COMException with the folder-parsing HRESULT when SHParseDisplayName(folderPath, ...) returns a failed HRESULT. SHParseDisplayName converts a parsing name (path) to an ITEMIDLIST; failure means the shell could not resolve the directory part of the supplied file path. The HRESULT is included as the error code so the exact shell failure is identifiable.","triggerScenarios":"The directory portion of filePath does not exist or is not a valid shell namespace; folderPath is null (Path.GetDirectoryName returned null for a root/invalid file path); the folder is on a disconnected network drive; the path contains illegal characters the shell rejects; insufficient permission to parse the namespace.","commonSituations":"OpenFolderAndSelectFile called with a path whose parent directory was deleted/moved; a UNC path to an offline share; a recently-removed USB drive; a path built from a stale MRU/recent-items list; a file path with no directory component (bare root).","solutions":["Confirm the parent directory of filePath exists before calling OpenFolderAndSelectFile.","Check the HRESULT in the exception (e.g. 0x80070002 = ERROR_FILE_NOT_FOUND, 0x80070003 = ERROR_PATH_NOT_FOUND) to pinpoint the shell error.","For network paths, ensure the share is online and accessible.","Guard against null folderPath (Path.GetDirectoryName can return null) before invoking the shell API."],"exampleFix":"// before\nvar folderPath = Path.GetDirectoryName(filePath);\nvar hrFolder = PInvoke.SHParseDisplayName(folderPath, null, out pidlFolder, 0, out _);\nif (hrFolder.Failed) throw new COMException(\"Failed to parse folder path\", hrFolder);\n\n// after — pre-validate and handle null\nvar folderPath = Path.GetDirectoryName(filePath);\nif (string.IsNullOrEmpty(folderPath) || !Directory.Exists(folderPath))\n    return; // or fall back to Process.Start(\"explorer.exe\", ...)\nvar hrFolder = PInvoke.SHParseDisplayName(folderPath, null, out pidlFolder, 0, out _);\nif (hrFolder.Failed) throw new COMException(\"Failed to parse folder path\", hrFolder);","handlingStrategy":"validation","validationCode":"var folder = Path.GetDirectoryName(filePath);\nif (string.IsNullOrEmpty(folder) || !Directory.Exists(folder))\n    return;","typeGuard":"null","tryCatchPattern":"try { Win32Helper.OpenFolderAndSelectFile(filePath); }\ncatch (COMException ex) when (ex.Message.Contains(\"folder path\"))\n{ Log.Warn(...); Process.Start(\"explorer.exe\", Path.GetDirectoryName(filePath)); }","preventionTips":["Check Directory.Exists on the parent folder before calling.","Guard against null folder paths from Path.GetDirectoryName.","Decode the HRESULT to distinguish not-found from access-denied.","For network paths, confirm the share is reachable first."],"tags":["win32","shell","com","filesystem"],"backgroundTag":null,"analyzedSha":"7fc63b07bbaa10a0f0b2601487913fcba9ed24b0","analyzedAt":"2026-08-13T14:54:20.914Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}