[M365DSCUtil] PSGallery returning error for Find-Module crashes DSC run
Symptoms
DSC run stops right after a module has finished its Test-TargetResource function. This occurred in our Azure DevOps release pipeline for 2 of our 4 release stages today. Logs show this error:
2020-09-25T05:15:44.7943627Z Job {DF973EF6-FEED-11EA-BBFA-00155D000415} :
2020-09-25T05:15:44.7944186Z MIResult: 1
2020-09-25T05:15:44.7945003Z Error Message: No match was found for the specified search criteria and module name 'Microsoft365DSC'. Try Get-PSRepository to see all available registered module repositories.
2020-09-25T05:15:44.7946233Z Message ID: NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage
2020-09-25T05:15:44.7947871Z Error Category: 13
2020-09-25T05:15:44.7948342Z Error Code: 13
2020-09-25T05:15:44.7948735Z Error Type: MI
Root Cause
Every DSC resource module contains a call to Add-M365DSCTelemetryEvent in the M365DSCUtil module. This function then calls Test-M365DSCNewVersionAvailable, which uses Find-Module to retrieve the version number of the latest release. The PSGallery site is currently reporting issues via a banner on their site and it seems as if Find-Module 'Microsoft365DSC' failed due to that. This caused an exception which stopped the DSC run. Nothing about this error was written to the Windows Event Log.
Solution Proposal
- Checking for a new M365DSC module version is not essential, so make sure the DSC run can continue regardless of errors caused by that check.
- Write errors happening during the version check to the Windows Event Log.
- It would improve maintainability and performance if the version check would happen only once at the beginning of the whole DSC run and if this functionality would be located in a more easily discoverable place (I didn't expect a version check to happen in a function called "Add-M365DSCTelemetryEvent").
Fixed with 1.20.1021.1