@@ -143,9 +143,9 @@ public override FindResults FindTags(string[] tags, bool includePrerelease, Reso
143
143
public override FindResults FindCommandOrDscResource ( string [ ] tags , bool includePrerelease , bool isSearchingForCommands , out ErrorRecord errRecord )
144
144
{
145
145
errRecord = new ErrorRecord (
146
- new InvalidOperationException ( $ "Find by CommandName or DSCResource is not supported for the repository '{ Repository . Name } '") ,
147
- "FindCommandOrDscResourceFailure" ,
148
- ErrorCategory . InvalidOperation ,
146
+ new InvalidOperationException ( $ "Find by CommandName or DSCResource is not supported for the repository '{ Repository . Name } '") ,
147
+ "FindCommandOrDscResourceFailure" ,
148
+ ErrorCategory . InvalidOperation ,
149
149
this ) ;
150
150
151
151
return new FindResults ( stringResponse : Utils . EmptyStrArray , hashtableResponse : emptyHashResponses , responseType : FindResponseType ) ;
@@ -431,25 +431,25 @@ private string HttpRequestCall(string requestUrl, out ErrorRecord errRecord)
431
431
catch ( HttpRequestException e )
432
432
{
433
433
errRecord = new ErrorRecord (
434
- exception : e ,
435
- "HttpRequestFallFailure" ,
436
- ErrorCategory . ConnectionError ,
434
+ exception : e ,
435
+ "HttpRequestFallFailure" ,
436
+ ErrorCategory . ConnectionError ,
437
437
this ) ;
438
438
}
439
439
catch ( ArgumentNullException e )
440
440
{
441
441
errRecord = new ErrorRecord (
442
- exception : e ,
443
- "HttpRequestFallFailure" ,
442
+ exception : e ,
443
+ "HttpRequestFallFailure" ,
444
444
ErrorCategory . ConnectionError ,
445
445
this ) ;
446
446
}
447
447
catch ( InvalidOperationException e )
448
448
{
449
449
errRecord = new ErrorRecord (
450
- exception : e ,
451
- "HttpRequestFallFailure" ,
452
- ErrorCategory . ConnectionError ,
450
+ exception : e ,
451
+ "HttpRequestFallFailure" ,
452
+ ErrorCategory . ConnectionError ,
453
453
this ) ;
454
454
}
455
455
@@ -480,25 +480,25 @@ private HttpContent HttpRequestCallForContent(string requestUrl, out ErrorRecord
480
480
catch ( HttpRequestException e )
481
481
{
482
482
errRecord = new ErrorRecord (
483
- exception : e ,
484
- "HttpRequestFailure" ,
485
- ErrorCategory . ConnectionError ,
483
+ exception : e ,
484
+ "HttpRequestFailure" ,
485
+ ErrorCategory . ConnectionError ,
486
486
this ) ;
487
487
}
488
488
catch ( ArgumentNullException e )
489
489
{
490
490
errRecord = new ErrorRecord (
491
- exception : e ,
492
- "HttpRequestFailure" ,
493
- ErrorCategory . InvalidData ,
491
+ exception : e ,
492
+ "HttpRequestFailure" ,
493
+ ErrorCategory . InvalidData ,
494
494
this ) ;
495
495
}
496
496
catch ( InvalidOperationException e )
497
497
{
498
498
errRecord = new ErrorRecord (
499
- exception : e ,
500
- "HttpRequestFailure" ,
501
- ErrorCategory . InvalidOperation ,
499
+ exception : e ,
500
+ "HttpRequestFailure" ,
501
+ ErrorCategory . InvalidOperation ,
502
502
this ) ;
503
503
}
504
504
@@ -565,9 +565,9 @@ private string FindNameGlobbing(string packageName, bool includePrerelease, int
565
565
if ( names . Length == 0 )
566
566
{
567
567
errRecord = new ErrorRecord (
568
- new ArgumentException ( "-Name '*' for NuGet.Server hosted feed repository is not supported" ) ,
569
- "FindNameGlobbingFailure" ,
570
- ErrorCategory . InvalidArgument ,
568
+ new ArgumentException ( "-Name '*' for NuGet.Server hosted feed repository is not supported" ) ,
569
+ "FindNameGlobbingFailure" ,
570
+ ErrorCategory . InvalidArgument ,
571
571
this ) ;
572
572
573
573
return string . Empty ;
@@ -601,9 +601,9 @@ private string FindNameGlobbing(string packageName, bool includePrerelease, int
601
601
else
602
602
{
603
603
errRecord = new ErrorRecord (
604
- new ArgumentException ( "-Name with wildcards is only supported for scenarios similar to the following examples: PowerShell*, *ShellGet, *Shell*." ) ,
605
- "FindNameGlobbingFailure" ,
606
- ErrorCategory . InvalidArgument ,
604
+ new ArgumentException ( "-Name with wildcards is only supported for scenarios similar to the following examples: PowerShell*, *ShellGet, *Shell*." ) ,
605
+ "FindNameGlobbingFailure" ,
606
+ ErrorCategory . InvalidArgument ,
607
607
this ) ;
608
608
609
609
return string . Empty ;
@@ -632,9 +632,9 @@ private string FindNameGlobbingWithTag(string packageName, string[] tags, bool i
632
632
if ( names . Length == 0 )
633
633
{
634
634
errRecord = new ErrorRecord (
635
- new ArgumentException ( "-Name '*' for NuGet.Server hosted feed repository is not supported" ) ,
636
- "FindNameGlobbingFailure" ,
637
- ErrorCategory . InvalidArgument ,
635
+ new ArgumentException ( "-Name '*' for NuGet.Server hosted feed repository is not supported" ) ,
636
+ "FindNameGlobbingFailure" ,
637
+ ErrorCategory . InvalidArgument ,
638
638
this ) ;
639
639
640
640
return string . Empty ;
@@ -668,9 +668,9 @@ private string FindNameGlobbingWithTag(string packageName, string[] tags, bool i
668
668
else
669
669
{
670
670
errRecord = new ErrorRecord (
671
- new ArgumentException ( "-Name with wildcards is only supported for scenarios similar to the following examples: PowerShell*, *ShellGet, *Shell*." ) ,
672
- "FindNameGlobbing" ,
673
- ErrorCategory . InvalidArgument ,
671
+ new ArgumentException ( "-Name with wildcards is only supported for scenarios similar to the following examples: PowerShell*, *ShellGet, *Shell*." ) ,
672
+ "FindNameGlobbing" ,
673
+ ErrorCategory . InvalidArgument ,
674
674
this ) ;
675
675
676
676
return string . Empty ;
@@ -780,16 +780,26 @@ private string FindVersionGlobbing(string packageName, VersionRange versionRange
780
780
/// Name: no wildcard support.
781
781
/// Examples: Install "PowerShellGet"
782
782
/// Implementation Note: {repoUri}/Packages(Id='test_local_mod')/Download
783
- /// if prerelease, call into InstallVersion instead.
783
+ /// if prerelease, call into InstallVersion instead.
784
784
/// </summary>
785
785
private Stream InstallName ( string packageName , out ErrorRecord errRecord )
786
786
{
787
787
_cmdletPassedIn . WriteDebug ( "In NuGetServerAPICalls::InstallName()" ) ;
788
788
var requestUrl = $ "{ Repository . Uri } /Packages/(Id='{ packageName } ')/Download";
789
789
var response = HttpRequestCallForContent ( requestUrl , out errRecord ) ;
790
- var responseStream = response . ReadAsStreamAsync ( ) . Result ;
791
790
792
- return responseStream ;
791
+ if ( response is null )
792
+ {
793
+ errRecord = new ErrorRecord (
794
+ new Exception ( $ "No content was returned by repository '{ Repository . Name } '") ,
795
+ "InstallFailureContentNullNuGetServer" ,
796
+ ErrorCategory . InvalidResult ,
797
+ this ) ;
798
+
799
+ return null ;
800
+ }
801
+
802
+ return response . ReadAsStreamAsync ( ) . Result ;
793
803
}
794
804
795
805
/// <summary>
@@ -799,15 +809,25 @@ private Stream InstallName(string packageName, out ErrorRecord errRecord)
799
809
/// Examples: Install "PowerShellGet" -Version "3.0.0.0"
800
810
/// Install "PowerShellGet" -Version "3.0.0-beta16"
801
811
/// API Call: {repoUri}/Packages(Id='Castle.Core',Version='5.1.1')/Download
802
- /// </summary>
812
+ /// </summary>
803
813
private Stream InstallVersion ( string packageName , string version , out ErrorRecord errRecord )
804
814
{
805
815
_cmdletPassedIn . WriteDebug ( "In NuGetServerAPICalls::InstallVersion()" ) ;
806
816
var requestUrl = $ "{ Repository . Uri } /Packages(Id='{ packageName } ',Version='{ version } ')/Download";
807
817
var response = HttpRequestCallForContent ( requestUrl , out errRecord ) ;
808
- var responseStream = response . ReadAsStreamAsync ( ) . Result ;
809
818
810
- return responseStream ;
819
+ if ( response is null )
820
+ {
821
+ errRecord = new ErrorRecord (
822
+ new Exception ( $ "No content was returned by repository '{ Repository . Name } '") ,
823
+ "InstallFailureContentNullNuGetServer" ,
824
+ ErrorCategory . InvalidResult ,
825
+ this ) ;
826
+
827
+ return null ;
828
+ }
829
+
830
+ return response . ReadAsStreamAsync ( ) . Result ;
811
831
}
812
832
813
833
/// <summary>
@@ -829,9 +849,9 @@ public int GetCountFromResponse(string httpResponse, out ErrorRecord errRecord)
829
849
catch ( XmlException e )
830
850
{
831
851
errRecord = new ErrorRecord (
832
- exception : e ,
833
- "GetCountFromResponse" ,
834
- ErrorCategory . InvalidData ,
852
+ exception : e ,
853
+ "GetCountFromResponse" ,
854
+ ErrorCategory . InvalidData ,
835
855
this ) ;
836
856
}
837
857
if ( errRecord != null )
@@ -886,7 +906,7 @@ public static async Task<HttpContent> SendRequestForContentAsync(HttpRequestMess
886
906
{
887
907
HttpResponseMessage response = await s_client . SendAsync ( message ) ;
888
908
response . EnsureSuccessStatusCode ( ) ;
889
-
909
+
890
910
return response . Content ;
891
911
}
892
912
catch ( HttpRequestException e )
0 commit comments