Skip to content

Commit

Permalink
Clean up error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamc committed Nov 25, 2023
1 parent b5a56d5 commit b5a4d15
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/cli/subcommand/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,15 @@ impl CommandExecute for Export {
#[tracing::instrument(level = "trace", skip_all)]
async fn execute(self) -> eyre::Result<ExitCode> {
let env = match calculate_environment() {
e @ Err(Error::AlreadyRun | Error::HomeNotSet) => {
e @ Err(Error::AlreadyRun) => {
debug!("Ignored error: {:?}", e);
return Ok(ExitCode::SUCCESS);
},
Err(e) => {
tracing::info!(
"Error calculating the environment variables required to enable Nix: {:?}",
e
);
return Err(e.into());
tracing::warn!("Error setting up the environment for Nix: {:?}", e);
// Don't return an Err, because we don't want to suggest bug reports for predictable problems.
return Ok(ExitCode::FAILURE);
},

Ok(env) => env,
};

Expand All @@ -106,15 +103,15 @@ impl CommandExecute for Export {
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"
.contains(char)
}) {
warn!("Key {} has an invalid character that isn't a-zA-Z_", key);
warn!("Key {} has an invalid character that isn't a-zA-Z0-9_", key);
return Ok(ExitCode::FAILURE);
}

let value_bytes = value.into_vec();

if value_bytes.contains(&b'\n') {
warn!(
"Value for key {} has an a newline, which is prohibited",
"Value for key {} has a newline, which is prohibited",
key
);
return Ok(ExitCode::FAILURE);
Expand Down

0 comments on commit b5a4d15

Please sign in to comment.