Skip to content

Commit

Permalink
config: Return default if sub-config key doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
shivaraj-bh committed Nov 29, 2024
1 parent 484a524 commit 21b7796
Showing 1 changed file with 1 addition and 12 deletions.
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

0 comments on commit 21b7796

Please sign in to comment.