Skip to content

Commit 551e52a

Browse files
committed
support dependencies across multiple namespaces
1 parent 75478f2 commit 551e52a

File tree

13 files changed

+336
-116
lines changed

13 files changed

+336
-116
lines changed

Cargo.lock

+41-27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+8-6
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ indexmap = { workspace = true }
3838
miette = { workspace = true, features = ["fancy"] }
3939
semver = { workspace = true }
4040
indicatif = { workspace = true, optional = true }
41+
warg-client = { workspace = true }
42+
dialoguer = "0.11.0"
4143

4244
[features]
43-
default = ["wit"]
45+
default = ["wit", "registry"]
4446
wat = ["wac-resolver/wat"]
4547
wit = ["wac-resolver/wit"]
4648
registry = ["wac-resolver/registry", "indicatif"]
@@ -71,11 +73,11 @@ wat = "1.202.0"
7173
logos = "0.14.0"
7274
miette = "7.2.0"
7375
thiserror = "1.0.58"
74-
warg-client = "0.4.1"
75-
warg-protocol = "0.4.1"
76-
warg-crypto = "0.4.1"
77-
warg-server = "0.4.1"
78-
warg-credentials = "0.4.1"
76+
warg-protocol = { git = "https://github.com/bytecodealliance/registry", branch = "namespace-enhancements" }
77+
warg-crypto = { git = "https://github.com/bytecodealliance/registry", branch = "namespace-enhancements" }
78+
warg-client = { git = "https://github.com/bytecodealliance/registry", branch = "namespace-enhancements" }
79+
warg-credentials = { git = "https://github.com/bytecodealliance/registry", branch = "namespace-enhancements" }
80+
warg-server = { git = "https://github.com/bytecodealliance/registry", branch = "namespace-enhancements" }
7981
secrecy = "0.8.0"
8082
futures = "0.3.30"
8183
indicatif = "0.17.8"

crates/wac-resolver/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ repository = { workspace = true }
1313
wac-types = { workspace = true }
1414
wac-parser = { workspace = true }
1515
semver = { workspace = true }
16-
thiserror = { workspace = true }
16+
thiserror.workspace = true
1717
anyhow = { workspace = true }
1818
log = { workspace = true }
1919
wit-component = { workspace = true }
@@ -28,6 +28,7 @@ warg-credentials = { workspace = true, optional = true }
2828
secrecy = { workspace = true, optional = true }
2929
tokio = { workspace = true, optional = true }
3030
futures = { workspace = true, optional = true }
31+
serde_json = "1.0.116"
3132

3233
[dev-dependencies]
3334
wac-graph = { workspace = true }

crates/wac-resolver/src/lib.rs

+66-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
//! Modules for package resolvers.
22
3+
use crate::Error as WacResolutionError;
4+
use anyhow::anyhow;
35
use indexmap::IndexMap;
46
use miette::{Diagnostic, SourceSpan};
5-
use wac_parser::Document;
7+
use thiserror::Error;
8+
use wac_parser::{resolution::Error as WacError, Document};
69

710
mod fs;
811
#[cfg(feature = "registry")]
@@ -14,6 +17,7 @@ pub use fs::*;
1417
pub use registry::*;
1518
pub use visitor::*;
1619
use wac_types::BorrowedPackageKey;
20+
use warg_client::ClientError;
1721

1822
/// Represents a package resolution error.
1923
#[derive(thiserror::Error, Diagnostic, Debug)]
@@ -149,3 +153,64 @@ pub fn packages<'a>(
149153
visitor.visit(document)?;
150154
Ok(keys)
151155
}
156+
157+
#[derive(Debug, Error)]
158+
/// Error for WAC commands
159+
pub enum CommandError {
160+
/// General errors
161+
#[error("Error: `{0}`")]
162+
General(anyhow::Error),
163+
/// Serde errors
164+
#[error("Error: `{0}`")]
165+
Serde(serde_json::Error),
166+
/// Wac resolution errors
167+
#[error("Error: `{0}`")]
168+
WacResolution(WacResolutionError),
169+
/// Wac errors
170+
#[error("Error: `{0}`")]
171+
Wac(WacError),
172+
/// Client Error
173+
#[error("Warg Client Error: {0}")]
174+
WargClient(ClientError),
175+
/// Client Error With Hint
176+
#[error("Warg Client Error: {0}")]
177+
WargHint(ClientError),
178+
}
179+
180+
/// Error from warg client
181+
pub struct WargClientError(pub ClientError);
182+
183+
impl std::fmt::Debug for WargClientError {
184+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
185+
f.debug_tuple("WargClientError").field(&self.0).finish()
186+
}
187+
}
188+
189+
impl From<anyhow::Error> for CommandError {
190+
fn from(value: anyhow::Error) -> Self {
191+
CommandError::General(value)
192+
}
193+
}
194+
195+
impl From<WacResolutionError> for CommandError {
196+
fn from(value: WacResolutionError) -> Self {
197+
CommandError::General(anyhow!(value))
198+
}
199+
}
200+
201+
impl From<serde_json::Error> for CommandError {
202+
fn from(value: serde_json::Error) -> Self {
203+
CommandError::Serde(value)
204+
}
205+
}
206+
207+
impl From<WargClientError> for CommandError {
208+
fn from(value: WargClientError) -> Self {
209+
match &value.0 {
210+
ClientError::PackageDoesNotExistWithHint { .. } => {
211+
CommandError::WargHint(value.0.into())
212+
}
213+
_ => CommandError::WargClient(value.0.into()),
214+
}
215+
}
216+
}

0 commit comments

Comments
 (0)