From 65d25b4b4a6176b835d0f34d045dbb673f7506b8 Mon Sep 17 00:00:00 2001 From: Anam Navied Date: Fri, 29 Sep 2023 15:48:13 -0400 Subject: [PATCH 1/5] provide more intuitive error message when JFrog feed is inactive --- src/code/V3ServerAPICalls.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/code/V3ServerAPICalls.cs b/src/code/V3ServerAPICalls.cs index 5128b25a3..988fd14f7 100644 --- a/src/code/V3ServerAPICalls.cs +++ b/src/code/V3ServerAPICalls.cs @@ -1474,11 +1474,23 @@ private JsonElement[] GetJsonElementArr(string request, string propertyName, out } catch (Exception e) { - errRecord = new ErrorRecord( - exception: e, - "GetResponsesFromRegistrationsResourceFailure", + if (e.Message.Contains("'<' is an invalid start of a value")) + { + // scenario where the feed is not active anymore, i.e confirmed for JFrogArtifactory. The default error message is not intuitive. + errRecord = new ErrorRecord( + exception: new Exception($"JSON response from repository {Repository.Name} could not be parsed due to the feed being inactive or invalid, with inner exception: {e.Message}"), + "FindVersionGlobbingFailure", ErrorCategory.InvalidResult, this); + } + else + { + errRecord = new ErrorRecord( + exception: e, + "GetResponsesFromRegistrationsResourceFailure", + ErrorCategory.InvalidResult, + this); + } } return entries; From e165ad9345d5bd28cdc570dedfbd22963e30bf3c Mon Sep 17 00:00:00 2001 From: Anam Navied Date: Fri, 29 Sep 2023 17:03:42 -0400 Subject: [PATCH 2/5] update RequiredResource test to have an empty inner hashtable scenario --- .../InstallPSResourceV2Server.Tests.ps1 | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/InstallPSResourceTests/InstallPSResourceV2Server.Tests.ps1 b/test/InstallPSResourceTests/InstallPSResourceV2Server.Tests.ps1 index 226c447cf..b64244dcd 100644 --- a/test/InstallPSResourceTests/InstallPSResourceV2Server.Tests.ps1 +++ b/test/InstallPSResourceTests/InstallPSResourceV2Server.Tests.ps1 @@ -389,15 +389,13 @@ Describe 'Test Install-PSResource for V2 Server scenarios' -tags 'CI' { repository = $PSGalleryName } - test_module2 = @{ + test_module2 = @{ version = "[1.0.0,3.0.0)" repository = $PSGalleryName prerelease = "true" } - TestModule99 = @{ - repository = $PSGalleryName - } + TestModule99 = @{} } Install-PSResource -RequiredResource $rrHash -TrustRepository From d29b038d7341b4ed2edd66fefb07d5c3bd897c99 Mon Sep 17 00:00:00 2001 From: Anam Navied Date: Tue, 3 Oct 2023 12:30:53 -0400 Subject: [PATCH 3/5] Revert "update RequiredResource test to have an empty inner hashtable scenario" This reverts commit e165ad9345d5bd28cdc570dedfbd22963e30bf3c. --- .../InstallPSResourceV2Server.Tests.ps1 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/InstallPSResourceTests/InstallPSResourceV2Server.Tests.ps1 b/test/InstallPSResourceTests/InstallPSResourceV2Server.Tests.ps1 index b64244dcd..226c447cf 100644 --- a/test/InstallPSResourceTests/InstallPSResourceV2Server.Tests.ps1 +++ b/test/InstallPSResourceTests/InstallPSResourceV2Server.Tests.ps1 @@ -389,13 +389,15 @@ Describe 'Test Install-PSResource for V2 Server scenarios' -tags 'CI' { repository = $PSGalleryName } - test_module2 = @{ + test_module2 = @{ version = "[1.0.0,3.0.0)" repository = $PSGalleryName prerelease = "true" } - TestModule99 = @{} + TestModule99 = @{ + repository = $PSGalleryName + } } Install-PSResource -RequiredResource $rrHash -TrustRepository From ec6fe9ae3c9947bee88793a884f17fe392edff92 Mon Sep 17 00:00:00 2001 From: Anam Navied Date: Wed, 4 Oct 2023 11:45:41 -0400 Subject: [PATCH 4/5] catch specific exception --- src/code/V3ServerAPICalls.cs | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/code/V3ServerAPICalls.cs b/src/code/V3ServerAPICalls.cs index 988fd14f7..6221e6f53 100644 --- a/src/code/V3ServerAPICalls.cs +++ b/src/code/V3ServerAPICalls.cs @@ -1472,25 +1472,22 @@ private JsonElement[] GetJsonElementArr(string request, string propertyName, out entries = responseEntries.ToArray(); } } + catch (JsonException e) + { + // scenario where the feed is not active anymore, i.e confirmed for JFrogArtifactory. The default error message is not intuitive. + errRecord = new ErrorRecord( + exception: new Exception($"JSON response from repository {Repository.Name} could not be parsed, likely due to the feed being inactive or invalid, with inner exception: {e.Message}"), + "FindVersionGlobbingFailure", + ErrorCategory.InvalidResult, + this); + } catch (Exception e) { - if (e.Message.Contains("'<' is an invalid start of a value")) - { - // scenario where the feed is not active anymore, i.e confirmed for JFrogArtifactory. The default error message is not intuitive. - errRecord = new ErrorRecord( - exception: new Exception($"JSON response from repository {Repository.Name} could not be parsed due to the feed being inactive or invalid, with inner exception: {e.Message}"), - "FindVersionGlobbingFailure", + errRecord = new ErrorRecord( + exception: e, + "GetResponsesFromRegistrationsResourceFailure", ErrorCategory.InvalidResult, this); - } - else - { - errRecord = new ErrorRecord( - exception: e, - "GetResponsesFromRegistrationsResourceFailure", - ErrorCategory.InvalidResult, - this); - } } return entries; From 8554746f27698d414a54ded704d99018e58a2ff6 Mon Sep 17 00:00:00 2001 From: Anam Navied Date: Wed, 4 Oct 2023 11:46:09 -0400 Subject: [PATCH 5/5] catch specific exception --- src/code/V3ServerAPICalls.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/code/V3ServerAPICalls.cs b/src/code/V3ServerAPICalls.cs index 6221e6f53..da70f6642 100644 --- a/src/code/V3ServerAPICalls.cs +++ b/src/code/V3ServerAPICalls.cs @@ -1476,10 +1476,10 @@ private JsonElement[] GetJsonElementArr(string request, string propertyName, out { // scenario where the feed is not active anymore, i.e confirmed for JFrogArtifactory. The default error message is not intuitive. errRecord = new ErrorRecord( - exception: new Exception($"JSON response from repository {Repository.Name} could not be parsed, likely due to the feed being inactive or invalid, with inner exception: {e.Message}"), - "FindVersionGlobbingFailure", - ErrorCategory.InvalidResult, - this); + exception: new Exception($"JSON response from repository {Repository.Name} could not be parsed, likely due to the feed being inactive or invalid, with inner exception: {e.Message}"), + "FindVersionGlobbingFailure", + ErrorCategory.InvalidResult, + this); } catch (Exception e) {