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

refactor: use miette instead of anyhow and ariadne #211

Merged
merged 4 commits into from
Jul 13, 2023
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
153 changes: 134 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ rustls-tls = ["reqwest/rustls-tls", "rattler_repodata_gateway/rustls-tls", "ratt
slow_integration_tests = []

[dependencies]
anyhow = "1.0.70"
ariadne = "0.3.0"
clap = { version = "4.2.4", default-features = false, features = ["derive", "usage", "wrap_help", "std", "color", "error-context"] }
clap-verbosity-flag = "2.0.1"
clap_complete = "4.2.1"
Expand All @@ -32,6 +30,7 @@ indicatif = "0.17.3"
insta = { version = "1.29.0", features = ["yaml"] }
is_executable = "1.0.1"
itertools = "0.10.5"
miette = { version = "5.9.0", features = ["fancy", "supports-color", "supports-hyperlinks", "supports-unicode", "terminal_size", "textwrap"] }
minijinja = { version = "0.34.0", features = ["builtins"] }
once_cell = "1.17.1"
rattler = { default-features = false, git = "https://github.com/mamba-org/rattler", branch = "main" }
Expand Down
19 changes: 10 additions & 9 deletions src/cli/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use crate::{
project::Project,
virtual_packages::get_minimal_virtual_packages,
};
use anyhow::Context;
use clap::Parser;
use indexmap::IndexMap;
use itertools::Itertools;
use miette::{IntoDiagnostic, WrapErr};
use rattler_conda_types::{
version_spec::VersionOperator, MatchSpec, NamelessMatchSpec, Platform, Version, VersionSpec,
};
Expand Down Expand Up @@ -69,7 +69,7 @@ impl SpecType {
}
}

pub async fn execute(args: Args) -> anyhow::Result<()> {
pub async fn execute(args: Args) -> miette::Result<()> {
let mut project = Project::load_or_else_discover(args.manifest_path.as_deref())?;
let spec_type = SpecType::from_args(&args);
add_specs_to_project(&mut project, args.specs, spec_type).await
Expand All @@ -79,15 +79,15 @@ pub async fn add_specs_to_project(
project: &mut Project,
specs: Vec<MatchSpec>,
spec_type: SpecType,
) -> anyhow::Result<()> {
) -> miette::Result<()> {
// Split the specs into package name and version specifier
let new_specs = specs
.into_iter()
.map(|spec| match &spec.name {
Some(name) => Ok((name.clone(), spec.into())),
None => Err(anyhow::anyhow!("missing package name for spec '{spec}'")),
None => Err(miette::miette!("missing package name for spec '{spec}'")),
})
.collect::<anyhow::Result<HashMap<String, NamelessMatchSpec>>>()?;
.collect::<miette::Result<HashMap<String, NamelessMatchSpec>>>()?;

// Get the current specs

Expand All @@ -111,7 +111,7 @@ pub async fn add_specs_to_project(
) {
Ok(versions) => versions,
Err(err) => {
return Err(err).context(anyhow::anyhow!(
return Err(err).wrap_err_with(||miette::miette!(
"could not determine any available versions for {} on {platform}. Either the package could not be found or version constraints on other dependencies result in a conflict.",
new_specs.keys().join(", ")
));
Expand Down Expand Up @@ -184,7 +184,7 @@ pub fn determine_best_version(
current_specs: &IndexMap<String, NamelessMatchSpec>,
sparse_repo_data: &[SparseRepoData],
platform: Platform,
) -> anyhow::Result<HashMap<String, Version>> {
) -> miette::Result<HashMap<String, Version>> {
let combined_specs = current_specs
.iter()
.chain(new_specs.iter())
Expand All @@ -204,7 +204,8 @@ pub fn determine_best_version(
platform_sparse_repo_data,
package_names.iter().cloned(),
None,
)?;
)
.into_diagnostic()?;

// Construct a solver task to start solving.
let task = rattler_solve::SolverTask {
Expand All @@ -226,7 +227,7 @@ pub fn determine_best_version(
pinned_packages: vec![],
};

let records = libsolv_rs::Solver.solve(task)?;
let records = libsolv_rs::Solver.solve(task).into_diagnostic()?;

// Determine the versions of the new packages
Ok(records
Expand Down
Loading