Flow-Launcher / Flow.Launcher

:mag: Quick file search & app launcher for Windows with community-made plugins
https://flowlauncher.com
MIT License
7.97k stars 310 forks source link

BUG: Windows search index throws exception when searching #2270

Closed Phoenix- closed 1 year ago

Phoenix- commented 1 year ago

Checks

Problem Description

Hey. Got a problem similar to https://github.com/Flow-Launcher/Flow.Launcher/issues/1630 Flow shows message 'Flow.Launcher.Plugin.Explorer.Exceptions.SearchException: Invalid URI: The Authority/Host could not be parsed.' as first result

Debugged it and I'm seeing that encodedFragmentPath var in WindowsIndex.cs:59 is containing only 'file:' and URI ctor fails. Did not dig deeper. Can do if needed, tho. Possible quick fix is just to wrap every result parsing with try-catch and just ignore invalid results, but thats a no-brainer from someone without knowledge on what's going on there.

Complete exception stack: WindowsIndex Search Exception: Flow.Launcher.Plugin.Explorer.Exceptions.SearchException: Invalid URI: The Authority/Host could not be parsed. ---> System.UriFormatException: Invalid URI: The Authority/Host could not be parsed. at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions) at Flow.Launcher.Plugin.Explorer.Search.WindowsIndex.WindowsIndex.ExecuteWindowsIndexSearchAsync(String indexQueryString, String connectionString, CancellationToken token)+MoveNext() in C:\projects\flow-launcher\Plugins\Flow.Launcher.Plugin.Explorer\Search\WindowsIndex\WindowsIndex.cs:line 70 at Flow.Launcher.Plugin.Explorer.Search.WindowsIndex.WindowsIndex.ExecuteWindowsIndexSearchAsync(String indexQueryString, String connectionString, CancellationToken token)+MoveNext() in C:\projects\flow-launcher\Plugins\Flow.Launcher.Plugin.Explorer\Search\WindowsIndex\WindowsIndex.cs:line 70 at Flow.Launcher.Plugin.Explorer.Search.WindowsIndex.WindowsIndex.ExecuteWindowsIndexSearchAsync(String indexQueryString, String connectionString, CancellationToken token)+MoveNext() in C:\projects\flow-launcher\Plugins\Flow.Launcher.Plugin.Explorer\Search\WindowsIndex\WindowsIndex.cs:line 70 at Flow.Launcher.Plugin.Explorer.Search.WindowsIndex.WindowsIndex.ExecuteWindowsIndexSearchAsync(String indexQueryString, String connectionString, CancellationToken token)+MoveNext() in C:\projects\flow-launcher\Plugins\Flow.Launcher.Plugin.Explorer\Search\WindowsIndex\WindowsIndex.cs:line 70 at Flow.Launcher.Plugin.Explorer.Search.WindowsIndex.WindowsIndex.ExecuteWindowsIndexSearchAsync(String indexQueryString, String connectionString, CancellationToken token)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult() at Flow.Launcher.Plugin.Explorer.Search.SearchManager.SearchAsync(Query query, CancellationToken token) in C:\projects\flow-launcher\Plugins\Flow.Launcher.Plugin.Explorer\Search\SearchManager.cs:line 129 at Flow.Launcher.Plugin.Explorer.Search.SearchManager.SearchAsync(Query query, CancellationToken token) in C:\projects\flow-launcher\Plugins\Flow.Launcher.Plugin.Explorer\Search\SearchManager.cs:line 129 --- End of inner exception stack trace --- at Flow.Launcher.Plugin.Explorer.Search.SearchManager.SearchAsync(Query query, CancellationToken token) in C:\projects\flow-launcher\Plugins\Flow.Launcher.Plugin.Explorer\Search\SearchManager.cs:line 129 at Flow.Launcher.Plugin.Explorer.Main.QueryAsync(Query query, CancellationToken token) in C:\projects\flow-launcher\Plugins\Flow.Launcher.Plugin.Explorer\Main.cs:line 88

To Reproduce

  1. Setup windows search SOMEHOW
  2. enable corresponding plugin, set everything to windows search.
  3. observe.

Screenshots

image

Flow Launcher Version

1.16.0

Windows Build Number

22H2 22621.1992

Error Log

Found nothing of interest there

jjw24 commented 1 year ago

Can you check for me please, if the Windows Search service is enabled/disabled or non-existent on your machine?

Phoenix- commented 1 year ago

Yes, windows search is enabled in extended mode, all drives are indexed.

jjw24 commented 1 year ago

This error should only happen if Windows Search service is non-existent if I remember correctly. So you are still getting this error even when enabled ?

Phoenix- commented 1 year ago

Yep, windows search service seems to work. I changed the code around like this

                SearchResult result;
                try
                {
                    var path = new Uri(encodedFragmentPath).LocalPath;
                    result = new SearchResult
                    {
                        FullPath = path,
                        Type = dataReader.GetString(2) == "Directory" ? ResultType.Folder : ResultType.File,
                        WindowsIndexed = true
                    };
                }
                catch
                {
                    continue;
                }

                yield return result;

and now search yields results.

jjw24 commented 1 year ago

Under what circumstance caused encodedFragmentPath to be half complete though? It shouldn't be just file:

Phoenix- commented 1 year ago

Cant pinpoint exact reason for invalid results. Searching for anything common like '1' yields lots of matches and some of them are invalid(file:). I have a strange feeling that is somehow fails around Starcraft-1 and Warcraft-3 maps with names like (4)Ruins of the Ancients.scm. No idea what's wrong with them.

jjw24 commented 1 year ago

What's encodedFragmentPath when you catch the exception?

Phoenix- commented 1 year ago

file: image

Phoenix- commented 1 year ago

There are multiple 'file:' results. All of them are located around valid results of Starcraft maps.

"file:"
Exception thrown: 'System.UriFormatException' in System.Private.Uri.dll
"file:C:/Games/StarCraft/Maps/BroodWar/(2)Astral Balance.scm"
"file:"
Exception thrown: 'System.UriFormatException' in System.Private.Uri.dll
"file:C:/Games/StarCraft/Maps/ladder/Season 10/(3)Ascension_1.0.scx"
"file:"
Exception thrown: 'System.UriFormatException' in System.Private.Uri.dll
"file:C:/Games/StarCraft/Maps/ladder/2018Season1/(3)Aztec 2.1.scx"
"file:"
Exception thrown: 'System.UriFormatException' in System.Private.Uri.dll
"file:C:/Games/StarCraft/Maps/ladder/2018Season2/(3)Aztec 2.1_iCCup.scx"
"file:E:/From Tecra/Warcraft III/Maps/(4)Adrenaline.w3m"
"file:E:/From Tecra/Warcraft III/Maps/FrozenThrone/(4)Adrenaline.w3x"
"file:"
Exception thrown: 'System.UriFormatException' in System.Private.Uri.dll
"file:C:/Games/StarCraft/Maps/ladder/Season 11/(4)Allegro_1.1b.scx"
"file:"
Exception thrown: 'System.UriFormatException' in System.Private.Uri.dll
"file:C:/Games/StarCraft/Maps/(4)Alpha Draconis.scm"
"file:"
Exception thrown: 'System.UriFormatException' in System.Private.Uri.dll
"file:C:/Games/StarCraft/Maps/BroodWar/(4)Archipelago.scm"
"file:"
Exception thrown: 'System.UriFormatException' in System.Private.Uri.dll
"file:C:/Games/StarCraft/Maps/BroodWar/(4)Arctic Station.scx"
"file:"
Exception thrown: 'System.UriFormatException' in System.Private.Uri.dll
"file:C:/Games/StarCraft/Maps/ladder/(4)Ashrigo.scm"
"file:E:/From Tecra/Warcraft III/Maps/FrozenThrone/(4)Avalanche.w3x"
"file:"
Exception thrown: 'System.UriFormatException' in System.Private.Uri.dll
"file:C:/Games/StarCraft/Maps/BroodWar/WebMaps/(4)Catwalk Alley.scm"
"file:"
Exception thrown: 'System.UriFormatException' in System.Private.Uri.dll
"file:C:/Games/StarCraft/Maps/ladder/2018Season2/(4)In the Way of an Eddy.scx"
"file:"
Exception thrown: 'System.UriFormatException' in System.Private.Uri.dll
"file:C:/Games/StarCraft/Maps/(4)Ruins of the Ancients.scm"
"file:"
Exception thrown: 'System.UriFormatException' in System.Private.Uri.dll
"file:C:/Games/StarCraft/Maps/BroodWar/(4)Space Atoll.scm"
"file:"
Exception thrown: 'System.UriFormatException' in System.Private.Uri.dll
"file:C:/Games/StarCraft/Maps/ladder/(6)Acropolis.scm"
"file:"
Exception thrown: 'System.UriFormatException' in System.Private.Uri.dll
"file:C:/Games/StarCraft/Maps/BroodWar/(6)Across the Cape.scm"

I dont see any 'file:' results in other directories

jjw24 commented 1 year ago

Can you try searching for files in one of those folders to see if you can narrow down the list

Phoenix- commented 1 year ago

If I understand it correctly - never worked with WS API - GetValue(0) is file name and GetValue(1) is the full path. when I get 'file:' for GetValue(1) I get correct file name for GetValue(0). Furthermore, next result yields same name with correct path. Looks like that WS DB is somehow corrupted. Or maybe some implementation weirdness.

Phoenix- commented 1 year ago

You have checks for DBNull in GetValue(0) or GetValue(1). Maybe just extend them to reject empty path?

jjw24 commented 1 year ago

GetValue(0) is file name and GetValue(1) is the full path.

Yes, and GetValue(2) would be the type of path.

when I get 'file:' for GetValue(1) I get correct file name for GetValue(0).

Are you saying the ones you get empty path on actual has a file name from GetValue(0)?

jjw24 commented 1 year ago

Furthermore, next result yields same name with correct path. Looks like that WS DB is somehow corrupted. Or maybe some implementation weirdness.

You have checks for DBNull in GetValue(0) or GetValue(1). Maybe just extend them to reject empty path?

Potentially could be if it is what you are saying, which means rebuilding index could solve this issue as a workaround (worth confirming afterwards). If it is the case then yes extend the checks to reject empty path would be the right fix.

I wasn't sure initially what's causing the empty path, but if it's from db corruption seeing you get duplicate entries of the same name but one with and one without path, then we should extend the check to cover this.

Phoenix- commented 1 year ago

Are you saying the ones you get empty path on actual has a file name from GetValue(0)?

Exactly. Some results come in pairs

  1. Name: '(2)Blue Storm 1.2_iCCup.scx' Path: 'file:'
  2. name '(2)Blue Storm 1.2_iCCup.scx' Path: 'file:C:/blah-blah/(2)Blue Storm 1.2_iCCup.scx'

I wasn't sure initially what's causing the empty path, but if it's from db corruption seeing you get duplicate entries of the same name but one with and one without path, then we should extend the check to cover this.

Yep. I moved SC folder between drives recently. Since then WS index is updated, so its not an issue of indexing in process. But maybe WS stores deleted entries. Or somehow fails to delete entries? Anyway, I doubt its worth digging into Windows internals. I'd say just ignore anything incorrect and call it a day.

jjw24 commented 1 year ago

Yes agree. Thank you for investigating this.

Could you fire up a pr for this please.

Phoenix- commented 1 year ago

Thanks! Filing PR in a moment.

jjw24 commented 1 year ago

Fixed and available in prerelease.