Skip to content

Commit

Permalink
fix: improve error message for missing plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Jun 20, 2024
1 parent 63739c8 commit 5c0741f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 16 deletions.
10 changes: 10 additions & 0 deletions src/backend/asdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::sync::{Arc, RwLock};

use clap::Command;
use color_eyre::eyre::{bail, eyre, Result, WrapErr};
use color_eyre::Section;
use console::style;
use itertools::Itertools;
use rayon::prelude::*;
Expand Down Expand Up @@ -150,6 +151,7 @@ impl Asdf {
return Ok(None);
}
let versions =
// using http is not a security concern and enabling tls makes mise significantly slower
match HTTP_FETCH.get_text(format!("http://mise-versions.jdx.dev/{}", self.name)) {
Err(err) if http::error_code(&err) == Some(404) => return Ok(None),
res => res?,
Expand Down Expand Up @@ -505,6 +507,14 @@ impl Backend for Asdf {
self.plugin_path.exists()
}

fn is_installed_err(&self) -> eyre::Result<()> {
if self.is_installed() {
return Ok(());
}
Err(eyre!("asdf plugin {} is not installed", self.id())
.suggestion("run with --yes to install plugin automatically"))
}

fn ensure_installed(&self, mpr: &MultiProgressReport, force: bool) -> Result<()> {
let config = Config::get();
let settings = Settings::try_get()?;
Expand Down
10 changes: 8 additions & 2 deletions src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::sync::{Arc, Mutex};
use clap::Command;
use console::style;
use contracts::requires;
use eyre::{bail, ensure, eyre, WrapErr};
use eyre::{bail, eyre, WrapErr};
use itertools::Itertools;
use rayon::prelude::*;
use regex::Regex;
Expand Down Expand Up @@ -295,6 +295,12 @@ pub trait Backend: Debug + Send + Sync {
fn is_installed(&self) -> bool {
true
}
fn is_installed_err(&self) -> eyre::Result<()> {
if self.is_installed() {
return Ok(());
}
bail!("{} is not installed", self.id())
}
fn ensure_installed(&self, _mpr: &MultiProgressReport, _force: bool) -> eyre::Result<()> {
Ok(())
}
Expand Down Expand Up @@ -345,7 +351,7 @@ pub trait Backend: Debug + Send + Sync {

#[requires(ctx.tv.backend.backend_type == self.get_type())]
fn install_version(&self, ctx: InstallContext) -> eyre::Result<()> {
ensure!(self.is_installed(), "{} is not installed", self.id());
self.is_installed_err()?;
let config = Config::get();
let settings = Settings::try_get()?;
if self.is_version_installed(&ctx.tv) {
Expand Down
25 changes: 11 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use std::process::exit;

use color_eyre::{Section, SectionExt};
use eyre::Report;
use itertools::Itertools;

use crate::cli::version::VERSION;
use crate::cli::Cli;
use crate::ui::style;

#[cfg(test)]
#[macro_use]
Expand Down Expand Up @@ -79,17 +76,17 @@ fn handle_err(err: Report) -> eyre::Result<()> {
return Ok(());
}
}
if log::max_level() < log::LevelFilter::Debug {
display_friendly_err(err);
exit(1);
}
// if log::max_level() < log::LevelFilter::Debug {
// display_friendly_err(err);
// exit(1);
// }
Err(err)
}

fn display_friendly_err(err: Report) {
for err in err.chain() {
error!("{err}");
}
let msg = style::edim("Run with --verbose or MISE_VERBOSE=1 for more information");
error!("{msg}");
}
// fn display_friendly_err(err: Report) {
// for err in err.chain() {
// error!("{err}");
// }
// let msg = style::edim("Run with --verbose or MISE_VERBOSE=1 for more information");
// error!("{msg}");
// }
1 change: 1 addition & 0 deletions src/plugins/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ impl CorePlugin {
if !*env::MISE_USE_VERSIONS_HOST {
return Ok(None);
}
// using http is not a security concern and enabling tls makes mise significantly slower
let raw = HTTP_FETCH.get_text(format!("http://mise-versions.jdx.dev/{}", &self.fa.name))?;
let versions = raw
.lines()
Expand Down
1 change: 1 addition & 0 deletions src/plugins/core/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ impl PythonPlugin {
fn fetch_precompiled_remote_versions(&self) -> eyre::Result<&Vec<(String, String, String)>> {
self.precompiled_cache.get_or_try_init(|| {
let settings = Settings::get();
// using http is not a security concern and enabling tls makes mise significantly slower
let raw = HTTP_FETCH.get_text("http://mise-versions.jdx.dev/python-precompiled")?;
let platform = format!("{}-{}", python_arch(&settings), python_os(&settings));
let versions = raw
Expand Down

0 comments on commit 5c0741f

Please sign in to comment.