Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return error message if specified adapter doesn't exist #506

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Return error message if specified adapter doesn't exist
SteveL-MSFT committed Jul 30, 2024
commit 4a8a1d5ef5381e158bbb7f9168e52234766eb6b8
6 changes: 6 additions & 0 deletions dsc/tests/dsc_resource_list.tests.ps1
Original file line number Diff line number Diff line change
@@ -66,4 +66,10 @@ Describe 'Tests for listing resources' {
$resource.capabilities | Should -Contain 'Get'
$resource.capabilities | Should -Contain 'Export'
}

It 'Invalid adapter returns an error' {
$out = dsc resource list --adapter 'foo*' 2>&1 | Out-String
$LASTEXITCODE | Should -Be 0
$out | Should -BeLike "*ERROR*Adapter 'foo`*' not found*"
}
}
6 changes: 6 additions & 0 deletions dsc_lib/src/discovery/command_discovery.rs
Original file line number Diff line number Diff line change
@@ -204,12 +204,14 @@ impl ResourceDiscovery for CommandDiscovery {

let mut adapted_resources = BTreeMap::<String, Vec<DscResource>>::new();

let mut found_adapter: bool = false;
for (adapter_name, adapters) in &self.adapters {
for adapter in adapters {
if !regex.is_match(adapter_name) {
continue;
}

found_adapter = true;
info!("Enumerating resources for adapter '{}'", adapter_name);
let pb_adapter_span = warn_span!("");
pb_adapter_span.pb_set_style(&ProgressStyle::with_template(
@@ -272,6 +274,10 @@ impl ResourceDiscovery for CommandDiscovery {
}
}

if !found_adapter {
return Err(DscError::AdapterNotFound(adapter_filter.to_string()));
}

self.adapted_resources = adapted_resources;
Ok(())
}
3 changes: 3 additions & 0 deletions dsc_lib/src/dscerror.rs
Original file line number Diff line number Diff line change
@@ -10,6 +10,9 @@ use tree_sitter::LanguageError;

#[derive(Error, Debug)]
pub enum DscError {
#[error("Adapter '{0}' not found")]
AdapterNotFound(String),

#[error("Function boolean argument conversion error: {0}")]
BooleanConversion(#[from] std::str::ParseBoolError),