microsoft / ReportingServicesTools

Reporting Services Powershell Tools
MIT License
458 stars 213 forks source link

Bug: Exception classes are not available for filtered catch statements #379

Open Pxtl opened 2 years ago

Pxtl commented 2 years ago

What is the current behavior?

When attempting to catch exceptions thrown by the ReportingServicesTools, the exceptions are of types that are not loaded and so can't be caught by type.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.

$proxy = New-RsWebServiceProxy -ReportServerUri https://myserver/myReportServiceasmx?wsdl
try {Get-RsDataSource -Proxy $proxy -Path '/Data Sources/Garbagename'}
catch [Microsoft.ReportingServices.Diagnostics.Utilities.ItemNotFoundException], [Microsoft.ReportingServices.Diagnostics.Utilities.InvalidItemPathException] {
  write-warning 'FAIL'
}

yields

Unable to find type [Microsoft.ReportingServices.Diagnostics.Utilities.ItemNotFoundException].
At line:2 char:7
+ catch [Microsoft.ReportingServices.Diagnostics.Utilities.InvalidItemP ...
+       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Microsoft.Repor...emPathException:TypeName) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : TypeNotFound

which is problematic since

$proxy = New-RsWebServiceProxy -ReportServerUri https://myserver/myReportServiceasmx?wsdl
try {Get-RsDataSource -Proxy $proxy -Path '/Data Sources/Garbagename'}

fails with

Exception while retrieving datasource! Exception calling "GetDataSourceContents" with "1" argument(s): "The item '/Data Sources/Garbagename' cannot be found. --->
Microsoft.ReportingServices.Diagnostics.Utilities.ItemNotFoundException: The item '/Data Sources/Garbagename' cannot be found."
At C:\Program Files\WindowsPowerShell\Modules\ReportingServicesTools\0.0.7.0\Functions\CatalogItems\Get-RsDataSource.ps1:83 char:17
+ ...             throw (New-Object System.Exception("Exception while retri ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], Exception
    + FullyQualifiedErrorId : Exception while retrieving datasource! Exception calling "GetDataSourceContents" with "1" argument(s): "The item '/Data Sources/Garbagename' cannot be found. ---
   > Microsoft.ReportingServices.Diagnostics.Utilities.ItemNotFoundException: The item '/Data Sources/Garbagename' cannot be found."

What is the expected behavior?

catching the given exceptions and yielding 'Warning: FAIL'

Which versions of Powershell and which OS are affected by this issue? Did this work in previous versions of our scripts?