Enable troubleshooting
This commit is contained in:
parent
765a5d2ef3
commit
c79a872438
2 changed files with 22 additions and 31 deletions
22
src/cli.rs
22
src/cli.rs
|
@ -272,29 +272,29 @@ pub async fn run() {
|
|||
use crate::troubleshooter::run_wrapped as r;
|
||||
|
||||
match opts.command {
|
||||
Command::Apply(args) => r(command::apply::run(hive, args)).await,
|
||||
Command::ApplyLocal(args) => r(command::apply_local::run(hive, args)).await,
|
||||
Command::Eval(args) => r(command::eval::run(hive, args)).await,
|
||||
Command::Exec(args) => r(command::exec::run(hive, args)).await,
|
||||
Command::NixInfo(args) => r(command::nix_info::run(args)).await,
|
||||
Command::Repl(args) => r(command::repl::run(hive, args)).await,
|
||||
Command::TestProgress => r(command::test_progress::run()).await,
|
||||
Command::Apply(args) => r(command::apply::run(hive, args), opts.config).await,
|
||||
Command::ApplyLocal(args) => r(command::apply_local::run(hive, args), opts.config).await,
|
||||
Command::Eval(args) => r(command::eval::run(hive, args), opts.config).await,
|
||||
Command::Exec(args) => r(command::exec::run(hive, args), opts.config).await,
|
||||
Command::NixInfo(args) => r(command::nix_info::run(args), opts.config).await,
|
||||
Command::Repl(args) => r(command::repl::run(hive, args), opts.config).await,
|
||||
Command::TestProgress => r(command::test_progress::run(), opts.config).await,
|
||||
Command::Build { deploy } => {
|
||||
let args = command::apply::Opts {
|
||||
deploy,
|
||||
goal: crate::nix::Goal::Build,
|
||||
node_filter: Default::default(),
|
||||
};
|
||||
r(command::apply::run(hive, args)).await
|
||||
},
|
||||
r(command::apply::run(hive, args), opts.config).await
|
||||
}
|
||||
Command::UploadKeys { deploy } => {
|
||||
let args = command::apply::Opts {
|
||||
deploy,
|
||||
goal: crate::nix::Goal::UploadKeys,
|
||||
node_filter: Default::default(),
|
||||
};
|
||||
r(command::apply::run(hive, args)).await
|
||||
},
|
||||
r(command::apply::run(hive, args), opts.config).await
|
||||
}
|
||||
Command::GenCompletions { shell } => print_completions(shell, &mut Opts::command()),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,13 +5,12 @@
|
|||
use std::env;
|
||||
use std::future::Future;
|
||||
|
||||
use clap::{parser::ValueSource as ClapValueSource, ArgMatches};
|
||||
use snafu::ErrorCompat;
|
||||
|
||||
use crate::error::ColmenaError;
|
||||
use crate::{error::ColmenaError, nix::HivePath};
|
||||
|
||||
/// Runs a closure and tries to troubleshoot if it returns an error.
|
||||
pub async fn run_wrapped<'a, F, T>(f: F) -> T
|
||||
pub async fn run_wrapped<'a, F, T>(f: F, hive_config: Option<HivePath>) -> T
|
||||
where
|
||||
F: Future<Output = Result<T, ColmenaError>>,
|
||||
{
|
||||
|
@ -21,13 +20,12 @@ where
|
|||
log::error!("-----");
|
||||
log::error!("Operation failed with error: {}", error);
|
||||
|
||||
// TODO: support troubleshooting
|
||||
// if let Err(own_error) = troubleshoot(hive, &error) {
|
||||
// log::error!(
|
||||
// "Error occurred while trying to troubleshoot another error: {}",
|
||||
// own_error
|
||||
// );
|
||||
// }
|
||||
if let Err(own_error) = troubleshoot(hive_config, &error) {
|
||||
log::error!(
|
||||
"Error occurred while trying to troubleshoot another error: {}",
|
||||
own_error
|
||||
);
|
||||
}
|
||||
|
||||
// Ensure we exit with a code
|
||||
quit::with_code(1);
|
||||
|
@ -35,17 +33,13 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
fn troubleshoot(
|
||||
global_args: &ArgMatches,
|
||||
_local_args: &ArgMatches,
|
||||
error: &ColmenaError,
|
||||
) -> Result<(), ColmenaError> {
|
||||
fn troubleshoot(hive_config: Option<HivePath>, error: &ColmenaError) -> Result<(), ColmenaError> {
|
||||
if let ColmenaError::NoFlakesSupport = error {
|
||||
// People following the tutorial might put hive.nix directly
|
||||
// in their Colmena checkout, and encounter NoFlakesSupport
|
||||
// because Colmena always prefers flake.nix when it exists.
|
||||
|
||||
if let Some(ClapValueSource::DefaultValue) = global_args.value_source("config") {
|
||||
if hive_config.is_none() {
|
||||
let cwd = env::current_dir()?;
|
||||
if cwd.join("flake.nix").is_file() && cwd.join("hive.nix").is_file() {
|
||||
eprintln!(
|
||||
|
@ -71,8 +65,5 @@ fn troubleshoot(
|
|||
}
|
||||
|
||||
fn backtrace_enabled() -> bool {
|
||||
match env::var("RUST_BACKTRACE") {
|
||||
Ok(backtrace_conf) => backtrace_conf != "0",
|
||||
_ => false,
|
||||
}
|
||||
matches!(env::var("RUST_BACKTRACE"), Ok(backtrace_conf) if backtrace_conf != "0")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue