@@ -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 ) ;
@@ -437,25 +437,25 @@ private string HttpRequestCall(string requestUrl, out ErrorRecord errRecord)
437
437
catch ( HttpRequestException e )
438
438
{
439
439
errRecord = new ErrorRecord (
440
- exception : e ,
441
- "HttpRequestFallFailure" ,
442
- ErrorCategory . ConnectionError ,
440
+ exception : e ,
441
+ "HttpRequestFallFailure" ,
442
+ ErrorCategory . ConnectionError ,
443
443
this ) ;
444
444
}
445
445
catch ( ArgumentNullException e )
446
446
{
447
447
errRecord = new ErrorRecord (
448
- exception : e ,
449
- "HttpRequestFallFailure" ,
448
+ exception : e ,
449
+ "HttpRequestFallFailure" ,
450
450
ErrorCategory . ConnectionError ,
451
451
this ) ;
452
452
}
453
453
catch ( InvalidOperationException e )
454
454
{
455
455
errRecord = new ErrorRecord (
456
- exception : e ,
457
- "HttpRequestFallFailure" ,
458
- ErrorCategory . ConnectionError ,
456
+ exception : e ,
457
+ "HttpRequestFallFailure" ,
458
+ ErrorCategory . ConnectionError ,
459
459
this ) ;
460
460
}
461
461
@@ -486,25 +486,25 @@ private HttpContent HttpRequestCallForContent(string requestUrl, out ErrorRecord
486
486
catch ( HttpRequestException e )
487
487
{
488
488
errRecord = new ErrorRecord (
489
- exception : e ,
490
- "HttpRequestFailure" ,
491
- ErrorCategory . ConnectionError ,
489
+ exception : e ,
490
+ "HttpRequestFailure" ,
491
+ ErrorCategory . ConnectionError ,
492
492
this ) ;
493
493
}
494
494
catch ( ArgumentNullException e )
495
495
{
496
496
errRecord = new ErrorRecord (
497
- exception : e ,
498
- "HttpRequestFailure" ,
499
- ErrorCategory . InvalidData ,
497
+ exception : e ,
498
+ "HttpRequestFailure" ,
499
+ ErrorCategory . InvalidData ,
500
500
this ) ;
501
501
}
502
502
catch ( InvalidOperationException e )
503
503
{
504
504
errRecord = new ErrorRecord (
505
- exception : e ,
506
- "HttpRequestFailure" ,
507
- ErrorCategory . InvalidOperation ,
505
+ exception : e ,
506
+ "HttpRequestFailure" ,
507
+ ErrorCategory . InvalidOperation ,
508
508
this ) ;
509
509
}
510
510
@@ -571,9 +571,9 @@ private string FindNameGlobbing(string packageName, bool includePrerelease, int
571
571
if ( names . Length == 0 )
572
572
{
573
573
errRecord = new ErrorRecord (
574
- new ArgumentException ( "-Name '*' for NuGet.Server hosted feed repository is not supported" ) ,
575
- "FindNameGlobbingFailure" ,
576
- ErrorCategory . InvalidArgument ,
574
+ new ArgumentException ( "-Name '*' for NuGet.Server hosted feed repository is not supported" ) ,
575
+ "FindNameGlobbingFailure" ,
576
+ ErrorCategory . InvalidArgument ,
577
577
this ) ;
578
578
579
579
return string . Empty ;
@@ -607,9 +607,9 @@ private string FindNameGlobbing(string packageName, bool includePrerelease, int
607
607
else
608
608
{
609
609
errRecord = new ErrorRecord (
610
- new ArgumentException ( "-Name with wildcards is only supported for scenarios similar to the following examples: PowerShell*, *ShellGet, *Shell*." ) ,
611
- "FindNameGlobbingFailure" ,
612
- ErrorCategory . InvalidArgument ,
610
+ new ArgumentException ( "-Name with wildcards is only supported for scenarios similar to the following examples: PowerShell*, *ShellGet, *Shell*." ) ,
611
+ "FindNameGlobbingFailure" ,
612
+ ErrorCategory . InvalidArgument ,
613
613
this ) ;
614
614
615
615
return string . Empty ;
@@ -638,9 +638,9 @@ private string FindNameGlobbingWithTag(string packageName, string[] tags, bool i
638
638
if ( names . Length == 0 )
639
639
{
640
640
errRecord = new ErrorRecord (
641
- new ArgumentException ( "-Name '*' for NuGet.Server hosted feed repository is not supported" ) ,
642
- "FindNameGlobbingFailure" ,
643
- ErrorCategory . InvalidArgument ,
641
+ new ArgumentException ( "-Name '*' for NuGet.Server hosted feed repository is not supported" ) ,
642
+ "FindNameGlobbingFailure" ,
643
+ ErrorCategory . InvalidArgument ,
644
644
this ) ;
645
645
646
646
return string . Empty ;
@@ -674,9 +674,9 @@ private string FindNameGlobbingWithTag(string packageName, string[] tags, bool i
674
674
else
675
675
{
676
676
errRecord = new ErrorRecord (
677
- new ArgumentException ( "-Name with wildcards is only supported for scenarios similar to the following examples: PowerShell*, *ShellGet, *Shell*." ) ,
678
- "FindNameGlobbing" ,
679
- ErrorCategory . InvalidArgument ,
677
+ new ArgumentException ( "-Name with wildcards is only supported for scenarios similar to the following examples: PowerShell*, *ShellGet, *Shell*." ) ,
678
+ "FindNameGlobbing" ,
679
+ ErrorCategory . InvalidArgument ,
680
680
this ) ;
681
681
682
682
return string . Empty ;
@@ -786,16 +786,26 @@ private string FindVersionGlobbing(string packageName, VersionRange versionRange
786
786
/// Name: no wildcard support.
787
787
/// Examples: Install "PowerShellGet"
788
788
/// Implementation Note: {repoUri}/Packages(Id='test_local_mod')/Download
789
- /// if prerelease, call into InstallVersion instead.
789
+ /// if prerelease, call into InstallVersion instead.
790
790
/// </summary>
791
791
private Stream InstallName ( string packageName , out ErrorRecord errRecord )
792
792
{
793
793
_cmdletPassedIn . WriteDebug ( "In NuGetServerAPICalls::InstallName()" ) ;
794
794
var requestUrl = $ "{ Repository . Uri } /Packages/(Id='{ packageName } ')/Download";
795
795
var response = HttpRequestCallForContent ( requestUrl , out errRecord ) ;
796
- var responseStream = response . ReadAsStreamAsync ( ) . Result ;
797
796
798
- return responseStream ;
797
+ if ( response is null )
798
+ {
799
+ errRecord = new ErrorRecord (
800
+ new Exception ( $ "No content was returned by repository '{ Repository . Name } '") ,
801
+ "InstallFailureContentNullNuGetServer" ,
802
+ ErrorCategory . InvalidResult ,
803
+ this ) ;
804
+
805
+ return null ;
806
+ }
807
+
808
+ return response . ReadAsStreamAsync ( ) . Result ;
799
809
}
800
810
801
811
/// <summary>
@@ -805,15 +815,25 @@ private Stream InstallName(string packageName, out ErrorRecord errRecord)
805
815
/// Examples: Install "PowerShellGet" -Version "3.0.0.0"
806
816
/// Install "PowerShellGet" -Version "3.0.0-beta16"
807
817
/// API Call: {repoUri}/Packages(Id='Castle.Core',Version='5.1.1')/Download
808
- /// </summary>
818
+ /// </summary>
809
819
private Stream InstallVersion ( string packageName , string version , out ErrorRecord errRecord )
810
820
{
811
821
_cmdletPassedIn . WriteDebug ( "In NuGetServerAPICalls::InstallVersion()" ) ;
812
822
var requestUrl = $ "{ Repository . Uri } /Packages(Id='{ packageName } ',Version='{ version } ')/Download";
813
823
var response = HttpRequestCallForContent ( requestUrl , out errRecord ) ;
814
- var responseStream = response . ReadAsStreamAsync ( ) . Result ;
815
824
816
- return responseStream ;
825
+ if ( response is null )
826
+ {
827
+ errRecord = new ErrorRecord (
828
+ new Exception ( $ "No content was returned by repository '{ Repository . Name } '") ,
829
+ "InstallFailureContentNullNuGetServer" ,
830
+ ErrorCategory . InvalidResult ,
831
+ this ) ;
832
+
833
+ return null ;
834
+ }
835
+
836
+ return response . ReadAsStreamAsync ( ) . Result ;
817
837
}
818
838
819
839
/// <summary>
@@ -835,9 +855,9 @@ public int GetCountFromResponse(string httpResponse, out ErrorRecord errRecord)
835
855
catch ( XmlException e )
836
856
{
837
857
errRecord = new ErrorRecord (
838
- exception : e ,
839
- "GetCountFromResponse" ,
840
- ErrorCategory . InvalidData ,
858
+ exception : e ,
859
+ "GetCountFromResponse" ,
860
+ ErrorCategory . InvalidData ,
841
861
this ) ;
842
862
}
843
863
if ( errRecord != null )
@@ -892,7 +912,7 @@ public static async Task<HttpContent> SendRequestForContentAsync(HttpRequestMess
892
912
{
893
913
HttpResponseMessage response = await s_client . SendAsync ( message ) ;
894
914
response . EnsureSuccessStatusCode ( ) ;
895
-
915
+
896
916
return response . Content ;
897
917
}
898
918
catch ( HttpRequestException e )
0 commit comments