diff --git a/src/code/FindHelper.cs b/src/code/FindHelper.cs index 20403865a..6a26fe732 100644 --- a/src/code/FindHelper.cs +++ b/src/code/FindHelper.cs @@ -191,7 +191,7 @@ public IEnumerable SearchFromRepository( resourceMetadata = repository.GetResourceAsync().GetAwaiter().GetResult(); } catch (Exception e){ - _cmdletPassedIn.WriteDebug("Error retrieving resource from repository: " + e.Message); + Utils.WriteVerboseOnCmdlet(_cmdletPassedIn, "Error retrieving resource from repository: " + e.Message); } if (resourceSearch == null || resourceMetadata == null) @@ -271,16 +271,16 @@ private IEnumerable FindFromPackageSourceSearchAPI( } catch (HttpRequestException ex) { + Utils.WriteVerboseOnCmdlet(_cmdletPassedIn, "FindHelper MetadataAsync()- error receiving package: " + ex.Message); if ((String.Equals(repositoryName, _psGalleryRepoName, StringComparison.InvariantCultureIgnoreCase) || String.Equals(repositoryName, _psGalleryScriptsRepoName, StringComparison.InvariantCultureIgnoreCase))) { - _cmdletPassedIn.WriteDebug(String.Format("Error receiving package from PSGallery. To check if this is due to a PSGallery outage check: https://aka.ms/psgallerystatus . Specific error: {0}", ex.Message)); - yield break; + _cmdletPassedIn.WriteWarning(String.Format("Error receiving package from PSGallery. To check if this is due to a PSGallery outage check: https://aka.ms/psgallerystatus . Specific error: {0}", ex.Message)); } } catch (Exception e) { - _cmdletPassedIn.WriteDebug(String.Format("Exception retrieving package {0} due to {1}.", pkgName, e.Message)); + Utils.WriteVerboseOnCmdlet(_cmdletPassedIn, "FindHelper MetadataAsync()- error receiving package: " + e.Message); } if (retrievedPkgs == null || retrievedPkgs.Count() == 0) @@ -330,16 +330,17 @@ private IEnumerable FindFromPackageSourceSearchAPI( } catch (HttpRequestException ex) { + Utils.WriteVerboseOnCmdlet(_cmdletPassedIn, "FindHelper SearchAsync()- error receiving package: " + ex.Message); if ((String.Equals(repositoryName, _psGalleryRepoName, StringComparison.InvariantCultureIgnoreCase) || String.Equals(repositoryName, _psGalleryScriptsRepoName, StringComparison.InvariantCultureIgnoreCase))) { - _cmdletPassedIn.WriteDebug(String.Format("Error receiving package from PSGallery. To check if this is due to a PSGallery outage check: https://aka.ms/psgallerystatus . Specific error: {0}", ex.Message)); + _cmdletPassedIn.WriteWarning(String.Format("Error receiving package from PSGallery. To check if this is due to a PSGallery outage check: https://aka.ms/psgallerystatus . Specific error: {0}", ex.Message)); } yield break; } catch (Exception e) { - _cmdletPassedIn.WriteDebug(String.Format("Exception retrieving package {0} due to {1}.", pkgName, e.Message)); + Utils.WriteVerboseOnCmdlet(_cmdletPassedIn, "FindHelper SearchAsync()- error receiving package: " + e.Message); yield break; } diff --git a/src/code/Utils.cs b/src/code/Utils.cs index 5715958f5..75101d060 100644 --- a/src/code/Utils.cs +++ b/src/code/Utils.cs @@ -16,6 +16,18 @@ namespace Microsoft.PowerShell.PowerShellGet.UtilClasses { internal static class Utils { + public static void WriteVerboseOnCmdlet( + PSCmdlet cmdlet, + string message) + { + cmdlet.InvokeCommand.InvokeScript( + script: $"Write-Verbose -Verbose -Message {message}", + useNewScope: true, + writeToPipeline: System.Management.Automation.Runspaces.PipelineResultTypes.None, + input: null, + args: null); + } + public static string[] FilterOutWildcardNames( string[] pkgNames, out string[] errorMsgs)