Skip to content

Commit f3d1b42

Browse files
authored
Merge pull request #1151 from SteveL-MSFT/ext-discover-error
Fix so that extension discovery failure doesn't fail entire discovery
2 parents b1306bd + 3a7958d commit f3d1b42

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

build.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,10 @@ if ($null -ne $packageType) {
243243
} else {
244244
if ($architecture -ne 'current') {
245245
write-verbose -verbose "Installing clippy for $architecture"
246-
& $rustup component add clippy --target $architecture
246+
rustup component add clippy --target $architecture
247247
} else {
248248
write-verbose -verbose "Installing clippy for current architecture"
249-
& $rustup component add clippy
249+
rustup component add clippy
250250
}
251251
}
252252
if ($LASTEXITCODE -ne 0) {

dsc/tests/dsc_extension_discover.tests.ps1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,19 @@ Describe 'Discover extension tests' {
128128
}
129129
$foundWideLine | Should -BeTrue
130130
}
131+
132+
It 'Failed extension discovery should not fail overall discovery' -Skip:(!$IsWindows) {
133+
try {
134+
# exclude finding powershell.exe
135+
$oldPath = $env:PATH
136+
$dscFolder = Split-Path (Get-Command dsc).Source -Parent
137+
$env:PATH = "$env:PROGRAMFILES\PowerShell\7;$dscFolder"
138+
$out = dsc -l warn resource list 2> $TestDrive/error.log | ConvertFrom-Json
139+
$LASTEXITCODE | Should -Be 0
140+
$out.Count | Should -BeGreaterThan 0
141+
(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)
142+
} finally {
143+
$env:PATH = $oldPath
144+
}
145+
}
131146
}

dsc_lib/locales/en-us.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ searchingForResources = "Searching for resources: %{resources}"
110110
foundResourceWithVersion = "Found matching resource '%{resource}' version %{version}"
111111
foundNonAdapterResources = "Found %{count} non-adapter resources"
112112
resourceMissingRequireAdapter = "Resource '%{resource}' is missing 'require_adapter' field."
113+
extensionDiscoverFailed = "Extension '%{extension}' failed to discover resources: %{error}"
113114

114115
[dscresources.commandResource]
115116
invokeGet = "Invoking get for '%{resource}'"

dsc_lib/src/discovery/command_discovery.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,13 @@ impl ResourceDiscovery for CommandDiscovery {
310310
for extension in self.extensions.values() {
311311
if extension.capabilities.contains(&ExtensionCapability::Discover) {
312312
debug!("{}", t!("discovery.commandDiscovery.callingExtension", extension = extension.type_name));
313-
let discovered_resources = extension.discover()?;
313+
let discovered_resources = match extension.discover() {
314+
Ok(res) => res,
315+
Err(e) => {
316+
warn!("{}", t!("discovery.commandDiscovery.extensionDiscoverFailed", extension = extension.type_name, error = e));
317+
continue;
318+
}
319+
};
314320
debug!("{}", t!("discovery.commandDiscovery.extensionFoundResources", extension = extension.type_name, count = discovered_resources.len()));
315321
for resource in discovered_resources {
316322
if regex.is_match(&resource.type_name) {

0 commit comments

Comments
 (0)