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

config: Return default if sub-config key doesn't exist #354

Merged
merged 4 commits into from
Dec 1, 2024
Merged
Changes from 2 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
13 changes: 1 addition & 12 deletions crates/omnix-common/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,7 @@ impl OmConfig {
// Get the config map, returning default if it doesn't exist
let config = match self.config.get::<T>(root_key)? {
Some(res) => res,
None => {
return if self.reference.is_empty() {
Ok((T::default(), &[]))
} else {
// Reference requires the config to exist.
Err(OmConfigError::UnexpectedAttribute(self.reference.join(".")))
};
}
None => return Ok((T::default(), &[])),
};

let default = "default".to_string();
Expand Down Expand Up @@ -129,10 +122,6 @@ pub enum OmConfigError {
#[error("Missing configuration attribute: {0}")]
MissingConfigAttribute(String),

/// Unexpected attribute
#[error("Unexpected attribute: {0}")]
UnexpectedAttribute(String),

/// A [nix_rs::command::NixCmdError]
#[error("Nix command error: {0}")]
NixCmdError(#[from] nix_rs::command::NixCmdError),
Expand Down