Skip to content

Commit

Permalink
fix env read in case it is required and a defualt is present
Browse files Browse the repository at this point in the history
  • Loading branch information
pranshi06 committed Oct 2, 2024
1 parent e19124a commit 7fcda2d
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions crates/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,16 @@ async fn update(context: Context<impl Environment>, calcite_ref_singleton: &Calc
// 2. throw an error if there is a problem reading the env var
(true, Some(default)) => {
let variable_value = context.environment.read(&Variable::new(env_var.name.clone()));
let variable_value_result = {
if variable_value == Err(ndc_calcite_schema::environment::Error::VariableNotPresent(Variable::new(env_var.name.clone()))) {
Ok(default.to_string())
} else {
Err(anyhow::Error::msg(format!("Error reading the env var: {}", env_var.name.clone())))
let variable_value_result = match variable_value {
Result::Ok(value) => Result::Ok(value),
Err(err) => {
if err == (ndc_calcite_schema::environment::Error::VariableNotPresent(Variable::new(env_var.name.clone()))) {
Ok(default.to_string())
} else {
Err(anyhow::Error::msg(format!("Error reading the env var: {}", env_var.name.clone())))
}
}?;
}
}?;
env_var_map.insert(env_var.name.clone(), variable_value_result);
}
// if not required and no default is present, return an empty value
Expand Down

0 comments on commit 7fcda2d

Please sign in to comment.