Skip to content

change WriteDebug in catch to WriteVerbose -Verbose #392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/code/FindHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public IEnumerable<PSResourceInfo> SearchFromRepository(
resourceMetadata = repository.GetResourceAsync<PackageMetadataResource>().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)
Expand Down Expand Up @@ -271,16 +271,16 @@ private IEnumerable<PSResourceInfo> 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)
Expand Down Expand Up @@ -330,16 +330,17 @@ private IEnumerable<PSResourceInfo> 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;
}

Expand Down
12 changes: 12 additions & 0 deletions src/code/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down