bostrot / PowerToysRunPluginWinget

Winget plugin for PowerToys Run
MIT License
255 stars 14 forks source link

Fix startup crash #15

Closed davidegiacometti closed 1 year ago

davidegiacometti commented 1 year ago

Hi!

Some PowerToys users have reported crash on startup when https://bostrot.github.io/PowerToysRunPluginWinget/pkgs.json is not reachable.

This PR is going to handle the crash.

Moved the loading logic in the plugin Init method. Correct wait for the async GetPackage method to complete.

Just curios: are you maintaining the pkgs.json ?

System.Net.Sockets.SocketException: No such host is known.
Source: System.Net.Sockets
TargetAssembly: System.Net.Sockets, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
TargetModule: System.Net.Sockets.dll
TargetSite: Void ThrowException(System.Net.Sockets.SocketError, System.Threading.CancellationToken)
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
at System.Net.Sockets.Socket.g__WaitForConnectWithCancellation|281_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)

System.Net.Http.HttpRequestException: No such host is known. (bostrot.github.io:443)
Source: System.Net.Http
TargetAssembly: System.Net.Http, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
TargetModule: System.Net.Http.dll
TargetSite: Void MoveNext()
at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.AddHttp11ConnectionAsync(QueueItem queueItem)
at System.Threading.Tasks.TaskCompletionSourceWithCancellation1.WaitWithCancellationAsync(CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.HttpConnectionWaiter1.WaitForConnectionAsync(Boolean async, CancellationToken requestCancellationToken)
at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
at Community.PowerToys.Run.Plugin.Winget.Main.GetPackages() in C:\Users\erict\Sync\Projects\PowerToys\src\modules\launcher\Plugins\Community.PowerToys.Run.Plugin.Winget\Main.cs:line 110
at System.Threading.Tasks.Task.<>c.b__128_0(Object state)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
bostrot commented 1 year ago

Great, thanks for the PR! I'll look at it later.

The pkgs.json is updated daily (see nightly branch).