diff --git a/powershai/lib/util.ps1 b/powershai/lib/util.ps1 index 9aa21d6..ece4646 100644 --- a/powershai/lib/util.ps1 +++ b/powershai/lib/util.ps1 @@ -609,7 +609,15 @@ function Confirm-PowershaiObjectSchema { $IsTypeValid = $true; } else { $ExpectedType = $KeySchema.type; - $IsTypeValid = $KeyValue -is $ExpectedType; + $ExpectedTypes = @($ExpectedType) + + if($ExpectedType -eq [int]){ + $ExpectedTypes += [int64]; + } + + [bool]$IsTypeValid = @( $ExpectedTypes | ?{ $KeyValue -is $_ }).count + + if(!$IsTypeValid){ @@ -620,7 +628,7 @@ function Confirm-PowershaiObjectSchema { $errors += @( "InvalidType:$CurrenType" - "Expected:"+$ExpectedType.name + "Expected:"+(@($ExpectedType|%{$_.name}) -Join ",") ) -Join "," } @@ -711,6 +719,8 @@ function Enter-PowershaiRetry { } } + $CheckDetails = @{} + $MustRetry = $true; $CurrentTry = 0; while($CurrentTry -lt $Retries){ @@ -743,6 +753,8 @@ function Enter-PowershaiRetry { $CheckScriptResult = $CheckScript.InvokeWithContext( $null, [psvariable]::new('_', $result)) | %{$_}; verbose "CheckScriptResult: $CheckScriptResult"; + $CheckDetails.CheckScriptResult = $CheckScriptResult; + if($CheckScriptResult -is [bool]){ verbose "Result is bool!"; return $CheckScriptResult; @@ -767,6 +779,7 @@ function Enter-PowershaiRetry { $SchemaValidation = Confirm-PowershaiObjectSchema $ResultObject $CheckScriptResult + $CheckDetails.SchemaValidation = $SchemaValidation; return $SchemaValidation.valid; } @@ -782,7 +795,12 @@ function Enter-PowershaiRetry { } } - throw "POWERSHAI_RETRY_MAXREACHED"; + + $error = New-PowershaiError POWERSHAI_RETRY_MAXREACHED -Props @{ + details = $CheckDetails + } + + throw $error; } diff --git a/tests/pester/001-core/005-cmdlets.tests.ps1 b/tests/pester/001-core/005-cmdlets.tests.ps1 index 3ca8e1b..50bfe41 100644 --- a/tests/pester/001-core/005-cmdlets.tests.ps1 +++ b/tests/pester/001-core/005-cmdlets.tests.ps1 @@ -28,6 +28,10 @@ Describe "Get-AiChat" -Tags "get-aichat" { return $CustomMessaege } + Mock -module powershai Get-AiModel { + return @{ tools = $false } + } + }