forked from DGNum/colmena
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;
|
use crate::troubleshooter::run_wrapped as r;
|
||||||
|
|
||||||
match opts.command {
|
match opts.command {
|
||||||
Command::Apply(args) => r(command::apply::run(hive, args)).await,
|
Command::Apply(args) => r(command::apply::run(hive, args), opts.config).await,
|
||||||
Command::ApplyLocal(args) => r(command::apply_local::run(hive, args)).await,
|
Command::ApplyLocal(args) => r(command::apply_local::run(hive, args), opts.config).await,
|
||||||
Command::Eval(args) => r(command::eval::run(hive, args)).await,
|
Command::Eval(args) => r(command::eval::run(hive, args), opts.config).await,
|
||||||
Command::Exec(args) => r(command::exec::run(hive, args)).await,
|
Command::Exec(args) => r(command::exec::run(hive, args), opts.config).await,
|
||||||
Command::NixInfo(args) => r(command::nix_info::run(args)).await,
|
Command::NixInfo(args) => r(command::nix_info::run(args), opts.config).await,
|
||||||
Command::Repl(args) => r(command::repl::run(hive, args)).await,
|
Command::Repl(args) => r(command::repl::run(hive, args), opts.config).await,
|
||||||
Command::TestProgress => r(command::test_progress::run()).await,
|
Command::TestProgress => r(command::test_progress::run(), opts.config).await,
|
||||||
Command::Build { deploy } => {
|
Command::Build { deploy } => {
|
||||||
let args = command::apply::Opts {
|
let args = command::apply::Opts {
|
||||||
deploy,
|
deploy,
|
||||||
goal: crate::nix::Goal::Build,
|
goal: crate::nix::Goal::Build,
|
||||||
node_filter: Default::default(),
|
node_filter: Default::default(),
|
||||||
};
|
};
|
||||||
r(command::apply::run(hive, args)).await
|
r(command::apply::run(hive, args), opts.config).await
|
||||||
},
|
}
|
||||||
Command::UploadKeys { deploy } => {
|
Command::UploadKeys { deploy } => {
|
||||||
let args = command::apply::Opts {
|
let args = command::apply::Opts {
|
||||||
deploy,
|
deploy,
|
||||||
goal: crate::nix::Goal::UploadKeys,
|
goal: crate::nix::Goal::UploadKeys,
|
||||||
node_filter: Default::default(),
|
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()),
|
Command::GenCompletions { shell } => print_completions(shell, &mut Opts::command()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,12 @@
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
|
|
||||||
use clap::{parser::ValueSource as ClapValueSource, ArgMatches};
|
|
||||||
use snafu::ErrorCompat;
|
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.
|
/// 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
|
where
|
||||||
F: Future<Output = Result<T, ColmenaError>>,
|
F: Future<Output = Result<T, ColmenaError>>,
|
||||||
{
|
{
|
||||||
|
@ -21,13 +20,12 @@ where
|
||||||
log::error!("-----");
|
log::error!("-----");
|
||||||
log::error!("Operation failed with error: {}", error);
|
log::error!("Operation failed with error: {}", error);
|
||||||
|
|
||||||
// TODO: support troubleshooting
|
if let Err(own_error) = troubleshoot(hive_config, &error) {
|
||||||
// if let Err(own_error) = troubleshoot(hive, &error) {
|
log::error!(
|
||||||
// log::error!(
|
"Error occurred while trying to troubleshoot another error: {}",
|
||||||
// "Error occurred while trying to troubleshoot another error: {}",
|
own_error
|
||||||
// own_error
|
);
|
||||||
// );
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// Ensure we exit with a code
|
// Ensure we exit with a code
|
||||||
quit::with_code(1);
|
quit::with_code(1);
|
||||||
|
@ -35,17 +33,13 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn troubleshoot(
|
fn troubleshoot(hive_config: Option<HivePath>, error: &ColmenaError) -> Result<(), ColmenaError> {
|
||||||
global_args: &ArgMatches,
|
|
||||||
_local_args: &ArgMatches,
|
|
||||||
error: &ColmenaError,
|
|
||||||
) -> Result<(), ColmenaError> {
|
|
||||||
if let ColmenaError::NoFlakesSupport = error {
|
if let ColmenaError::NoFlakesSupport = error {
|
||||||
// People following the tutorial might put hive.nix directly
|
// People following the tutorial might put hive.nix directly
|
||||||
// in their Colmena checkout, and encounter NoFlakesSupport
|
// in their Colmena checkout, and encounter NoFlakesSupport
|
||||||
// because Colmena always prefers flake.nix when it exists.
|
// 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()?;
|
let cwd = env::current_dir()?;
|
||||||
if cwd.join("flake.nix").is_file() && cwd.join("hive.nix").is_file() {
|
if cwd.join("flake.nix").is_file() && cwd.join("hive.nix").is_file() {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
|
@ -71,8 +65,5 @@ fn troubleshoot(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn backtrace_enabled() -> bool {
|
fn backtrace_enabled() -> bool {
|
||||||
match env::var("RUST_BACKTRACE") {
|
matches!(env::var("RUST_BACKTRACE"), Ok(backtrace_conf) if backtrace_conf != "0")
|
||||||
Ok(backtrace_conf) => backtrace_conf != "0",
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue