Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: raise error if resolve fails and is a CLI argument #2136

Merged
merged 1 commit into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
use eyre::Report;
use std::process::ExitStatus;

use crate::toolset::{ToolRequest, ToolSource};
use thiserror::Error;

#[derive(Debug, Error)]
pub enum Error {
#[error("Failed to resolve {tr} from {ts}: {source:#}")]
FailedToResolveVersion {
tr: ToolRequest,
ts: ToolSource,
source: Report,
},
#[error("[{0}] plugin not installed")]
PluginNotInstalled(String),
#[error("{0}@{1} not installed")]
Expand All @@ -20,3 +28,19 @@ fn render_exit_status(exit_status: &Option<ExitStatus>) -> String {
None => "no exit status".into(),
}
}

impl Error {
pub fn is_argument_err(err: &Report) -> bool {
err.downcast_ref::<Error>()
.map(|e| {
matches!(
e,
Error::FailedToResolveVersion {
ts: ToolSource::Argument,
..
}
)
})
.unwrap_or(false)
}
}
4 changes: 4 additions & 0 deletions src/toolset/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use itertools::Itertools;

use crate::cli::args::{ForgeArg, ToolArg};
use crate::config::{Config, Settings};
use crate::errors::Error;
use crate::toolset::{ToolRequest, ToolSource, Toolset};
use crate::{config, env};

Expand Down Expand Up @@ -60,6 +61,9 @@ impl ToolsetBuilder {
self.load_runtime_env(&mut toolset, env::vars().collect())?;
self.load_runtime_args(&mut toolset)?;
if let Err(err) = toolset.resolve() {
if Error::is_argument_err(&err) {
return Err(err);
}
warn!("failed to resolve toolset: {err:#}");
}

Expand Down
9 changes: 7 additions & 2 deletions src/toolset/tool_version_list.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::cli::args::ForgeArg;
use crate::errors::Error;
use crate::forge;
use crate::toolset::tool_version_request::ToolRequest;
use crate::toolset::{ToolSource, ToolVersion};
Expand Down Expand Up @@ -28,8 +29,12 @@ impl ToolVersionList {
match tvr.resolve(plugin.as_ref(), latest_versions) {
Ok(v) => self.versions.push(v),
Err(err) => {
let source = self.source.to_string();
bail!("failed to resolve version of {plugin} from {source}: {err:#}");
return Err(Error::FailedToResolveVersion {
tr: tvr.clone(),
ts: self.source.clone(),
source: err,
}
.into());
}
}
}
Expand Down
Loading