From b4bc1773ce2dcc4b9ae3ab149b8a4d2a3ee051d5 Mon Sep 17 00:00:00 2001 From: "Steve Lee (POWERSHELL HE/HIM) (from Dev Box)" Date: Wed, 1 Oct 2025 14:12:29 -0700 Subject: [PATCH 1/3] Fix so that extension discovery failure doesn't fail entire discovery --- dsc/tests/dsc_extension_discover.tests.ps1 | 14 ++++++++++++++ dsc_lib/locales/en-us.toml | 1 + dsc_lib/src/discovery/command_discovery.rs | 8 +++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/dsc/tests/dsc_extension_discover.tests.ps1 b/dsc/tests/dsc_extension_discover.tests.ps1 index 03da8c429..70fbf5250 100644 --- a/dsc/tests/dsc_extension_discover.tests.ps1 +++ b/dsc/tests/dsc_extension_discover.tests.ps1 @@ -128,4 +128,18 @@ Describe 'Discover extension tests' { } $foundWideLine | Should -BeTrue } + + It 'Failed extension discovery should not fail overall discovery' -Skip:(!$IsWindows) { + try { + # exclude finding powershell.exe + $oldPath = $env:PATH + $env:PATH = $env:PATH="$env:PROGRAMFILES\PowerShell\7" + $out = dsc resource list 2> $TestDrive/error.log | ConvertFrom-Json + $LASTEXITCODE | Should -Be 0 + $out.Count | Should -BeGreaterThan 0 + (Get-Content -Path "$TestDrive/error.log" -Raw) | Should -BeLike "WARN Extension 'Microsoft.Windows.Appx/Discover' failed to discover resources: Command: Operation program not found for executable 'powershell'" -Because (Get-Content -Path "$TestDrive/error.log" -Raw | Out-String) + } finally { + $env:PATH = $oldPath + } + } } diff --git a/dsc_lib/locales/en-us.toml b/dsc_lib/locales/en-us.toml index 29a4bb792..7bc1971ce 100644 --- a/dsc_lib/locales/en-us.toml +++ b/dsc_lib/locales/en-us.toml @@ -110,6 +110,7 @@ searchingForResources = "Searching for resources: %{resources}" foundResourceWithVersion = "Found matching resource '%{resource}' version %{version}" foundNonAdapterResources = "Found %{count} non-adapter resources" resourceMissingRequireAdapter = "Resource '%{resource}' is missing 'require_adapter' field." +extensionDiscoverFailed = "Extension '%{extension}' failed to discover resources: %{error}" [dscresources.commandResource] invokeGet = "Invoking get for '%{resource}'" diff --git a/dsc_lib/src/discovery/command_discovery.rs b/dsc_lib/src/discovery/command_discovery.rs index a576c4323..98b6279b9 100644 --- a/dsc_lib/src/discovery/command_discovery.rs +++ b/dsc_lib/src/discovery/command_discovery.rs @@ -310,7 +310,13 @@ impl ResourceDiscovery for CommandDiscovery { for extension in self.extensions.values() { if extension.capabilities.contains(&ExtensionCapability::Discover) { debug!("{}", t!("discovery.commandDiscovery.callingExtension", extension = extension.type_name)); - let discovered_resources = extension.discover()?; + let discovered_resources = match extension.discover() { + Ok(res) => res, + Err(e) => { + warn!("{}", t!("discovery.commandDiscovery.extensionDiscoverFailed", extension = extension.type_name, error = e).to_string()); + continue; + } + }; debug!("{}", t!("discovery.commandDiscovery.extensionFoundResources", extension = extension.type_name, count = discovered_resources.len())); for resource in discovered_resources { if regex.is_match(&resource.type_name) { From e64f94ccb696b3f120d5ed33c397baca9d5774de Mon Sep 17 00:00:00 2001 From: "Steve Lee (POWERSHELL HE/HIM) (from Dev Box)" Date: Wed, 1 Oct 2025 14:19:27 -0700 Subject: [PATCH 2/3] fix tests and install clippy with rustup --- build.ps1 | 4 ++-- dsc/tests/dsc_extension_discover.tests.ps1 | 4 ++-- dsc_lib/src/discovery/command_discovery.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build.ps1 b/build.ps1 index 6c238faed..b19abbbf9 100755 --- a/build.ps1 +++ b/build.ps1 @@ -243,10 +243,10 @@ if ($null -ne $packageType) { } else { if ($architecture -ne 'current') { write-verbose -verbose "Installing clippy for $architecture" - & $rustup component add clippy --target $architecture + rustup component add clippy --target $architecture } else { write-verbose -verbose "Installing clippy for current architecture" - & $rustup component add clippy + rustup component add clippy } } if ($LASTEXITCODE -ne 0) { diff --git a/dsc/tests/dsc_extension_discover.tests.ps1 b/dsc/tests/dsc_extension_discover.tests.ps1 index 70fbf5250..c1095d326 100644 --- a/dsc/tests/dsc_extension_discover.tests.ps1 +++ b/dsc/tests/dsc_extension_discover.tests.ps1 @@ -133,11 +133,11 @@ Describe 'Discover extension tests' { try { # exclude finding powershell.exe $oldPath = $env:PATH - $env:PATH = $env:PATH="$env:PROGRAMFILES\PowerShell\7" + $env:PATH = "$env:PROGRAMFILES\PowerShell\7" $out = dsc resource list 2> $TestDrive/error.log | ConvertFrom-Json $LASTEXITCODE | Should -Be 0 $out.Count | Should -BeGreaterThan 0 - (Get-Content -Path "$TestDrive/error.log" -Raw) | Should -BeLike "WARN Extension 'Microsoft.Windows.Appx/Discover' failed to discover resources: Command: Operation program not found for executable 'powershell'" -Because (Get-Content -Path "$TestDrive/error.log" -Raw | Out-String) + (Get-Content -Path "$TestDrive/error.log" -Raw) | Should -BeLike "*WARN Extension 'Microsoft.Windows.Appx/Discover' failed to discover resources: Command: Operation program not found for executable 'powershell'*" -Because (Get-Content -Path "$TestDrive/error.log" -Raw | Out-String) } finally { $env:PATH = $oldPath } diff --git a/dsc_lib/src/discovery/command_discovery.rs b/dsc_lib/src/discovery/command_discovery.rs index 98b6279b9..cf30a7fc1 100644 --- a/dsc_lib/src/discovery/command_discovery.rs +++ b/dsc_lib/src/discovery/command_discovery.rs @@ -313,7 +313,7 @@ impl ResourceDiscovery for CommandDiscovery { let discovered_resources = match extension.discover() { Ok(res) => res, Err(e) => { - warn!("{}", t!("discovery.commandDiscovery.extensionDiscoverFailed", extension = extension.type_name, error = e).to_string()); + warn!("{}", t!("discovery.commandDiscovery.extensionDiscoverFailed", extension = extension.type_name, error = e)); continue; } }; From 3a7958df2da5d171d183720bb600a4b4babfe65b Mon Sep 17 00:00:00 2001 From: "Steve Lee (POWERSHELL HE/HIM) (from Dev Box)" Date: Thu, 2 Oct 2025 12:12:20 -0700 Subject: [PATCH 3/3] fix test --- dsc/tests/dsc_extension_discover.tests.ps1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dsc/tests/dsc_extension_discover.tests.ps1 b/dsc/tests/dsc_extension_discover.tests.ps1 index c1095d326..043713536 100644 --- a/dsc/tests/dsc_extension_discover.tests.ps1 +++ b/dsc/tests/dsc_extension_discover.tests.ps1 @@ -133,8 +133,9 @@ Describe 'Discover extension tests' { try { # exclude finding powershell.exe $oldPath = $env:PATH - $env:PATH = "$env:PROGRAMFILES\PowerShell\7" - $out = dsc resource list 2> $TestDrive/error.log | ConvertFrom-Json + $dscFolder = Split-Path (Get-Command dsc).Source -Parent + $env:PATH = "$env:PROGRAMFILES\PowerShell\7;$dscFolder" + $out = dsc -l warn resource list 2> $TestDrive/error.log | ConvertFrom-Json $LASTEXITCODE | Should -Be 0 $out.Count | Should -BeGreaterThan 0 (Get-Content -Path "$TestDrive/error.log" -Raw) | Should -BeLike "*WARN Extension 'Microsoft.Windows.Appx/Discover' failed to discover resources: Command: Operation program not found for executable 'powershell'*" -Because (Get-Content -Path "$TestDrive/error.log" -Raw | Out-String)