MethodsAndPractices / vsteam

PowerShell module for accessing Azure DevOps Services and Azure DevOps Server (formerly VSTS or TFS)
https://methodsandpractices.github.io/vsteam-docs/
MIT License
442 stars 155 forks source link

Import-Module 7.6.0 and 7.6.1 throws error in disconnected environments #466

Closed PeterLefebvre closed 1 year ago

PeterLefebvre commented 2 years ago

Steps to reproduce

Get-NetAdapter Ethernet | ft Name, Status
test-connection github.com -count 1 | ft Address, IPV4Address, ReplySize, ResponseTime

Get-NetAdapter Ethernet | Disable-NetAdapter -Confirm:$false
start-sleep -Seconds 10
Get-NetAdapter Ethernet | ft Name, Status
test-connection github.com -count 1 | ft Address, IPV4Address, ReplySize, ResponseTime

get-module vsteam | ft
import-module vsteam -RequiredVersion 7.6.1 
(get-vsteaminfo).ModuleVersion | ft
remove-module vsteam 

get-module vsteam | ft
import-module vsteam -RequiredVersion 7.6.0
(get-vsteaminfo).ModuleVersion  | ft
remove-module vsteam 

Expected behavior

I expected that...

in disconnected environments, the import-module does not fail.

Actual behavior?

I had the following actual outcome...

==> for 7.6.1
Exception calling "Send" with "2" argument(s): "An exception occurred during a Ping request."
At D:\Users\XXX\Documents\WindowsPowerShell\Modules\vsteam\7.6.1\vsteam.functions.ps1:1050 char:4
+    [System.Net.NetworkInformation.PingReply]$reply = $pingGh.Send('gi ...
+    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : PingException

Exception calling "Send" with "2" argument(s): "An exception occurred during a Ping request."
At D:\Users\XXX\Documents\WindowsPowerShell\Modules\vsteam\7.6.1\vsteam.functions.ps1:1050 char:4
+    [System.Net.NetworkInformation.PingReply]$reply = $pingGh.Send('gi ...
+    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : PingException

==> For 7.6.0
Exception calling "Send" with "2" argument(s): "An exception occurred during a Ping request."
At D:\Users\XXX\Documents\WindowsPowerShell\Modules\vsteam\7.6.0\vsteam.functions.ps1:1050 char:4
+    [System.Net.NetworkInformation.PingReply]$reply = $pingGh.Send('gi ...
+    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : PingException

Exception calling "Send" with "2" argument(s): "An exception occurred during a Ping request."
At D:\Users\XXX\Documents\WindowsPowerShell\Modules\vsteam\7.6.0\vsteam.functions.ps1:1050 char:4
+    [System.Net.NetworkInformation.PingReply]$reply = $pingGh.Send('gi ...
+    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : PingException

I encountered this first at work, as we have a rather restricted environment. Ping and test-connection to github.com gets blocked or the DNS cannot be resolved correctly. Using a Browser I can go to github.com, but we pass a forced proxy.

In 'interactive mode', I can ignore the errors, but when running in a CI/CD pipeline, I fear this could be problematic.

Have not seen this behaviour yet in versions below 7.6.0.

PS: Above steps to reproduce is from my home workstation, where I just simulated the behaviour with a disabled network adapter.

On Which OS have you tried it?

Windows

What was your server version?

other (specify)

Other server version

not even connected to server yet, error message thrown at import

Log output of used API

N/A yet, during import-module

Log output of $PSVersionTable

Name                           Value                                                                                                                                                                                     
----                           -----                                                                                                                                                                                     
PSVersion                      5.1.19041.1320                                                                                                                                                                            
PSEdition                      Desktop                                                                                                                                                                                   
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                                                   
BuildVersion                   10.0.19041.1320                                                                                                                                                                           
CLRVersion                     4.0.30319.42000                                                                                                                                                                           
WSManStackVersion              3.0                                                                                                                                                                                       
PSRemotingProtocolVersion      2.3                                                                                                                                                                                       
SerializationVersion           1.1.0.1
SebastianSchuetze commented 1 year ago

Thanks for reporting. Working on it now to make sure no exception is thrown if there is no ping possible. In that case I would return a "no sucess" from the ping.

SebastianSchuetze commented 1 year ago

Fixed it and changed the output when those functions are used from "debug" to "information" so they can be output and give information why and when this is used. But it should not throw an exception anymore.