Skip to content

Commit f5126b1

Browse files
committed
package display impl
clippy cleand up logging typos ./crates --write-changes
1 parent 5221bdc commit f5126b1

File tree

9 files changed

+57
-34
lines changed

9 files changed

+57
-34
lines changed

crates/wasm-pkg-client/src/caching/file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl Cache for FileCache {
8282
Error::CacheError(anyhow::anyhow!("Unable to create file for cache {e}"))
8383
})?;
8484
let mut buf =
85-
StreamReader::new(data.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e)));
85+
StreamReader::new(data.map_err(std::io::Error::other));
8686
tokio::io::copy(&mut buf, &mut file)
8787
.await
8888
.map_err(|e| Error::CacheError(e.into()))

crates/wasm-pkg-client/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,7 @@ impl Client {
168168
let (mut data, p, v) = tokio::task::spawn_blocking(|| resolve_package(data))
169169
.await
170170
.map_err(|e| {
171-
crate::Error::IoError(std::io::Error::new(
172-
std::io::ErrorKind::Other,
171+
crate::Error::IoError(std::io::Error::other(
173172
format!("Error when performing blocking IO: {e:?}"),
174173
))
175174
})??;
@@ -224,7 +223,7 @@ impl Client {
224223
self.config
225224
.namespace_registry(package.namespace())
226225
.and_then(|meta| {
227-
// If the overriden registry matches the registry we are trying to resolve, we
226+
// If the overridden registry matches the registry we are trying to resolve, we
228227
// should use the metadata, otherwise we'll need to fetch the metadata from the
229228
// registry
230229
match (meta, is_override) {

crates/wasm-pkg-client/src/release.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl Ord for VersionInfo {
2626

2727
impl PartialOrd for VersionInfo {
2828
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
29-
Some(self.version.cmp(&other.version))
29+
Some(self.cmp(other))
3030
}
3131
}
3232

crates/wasm-pkg-common/src/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl RegistryMetadata {
6363
}
6464

6565
/// Returns an iterator of protocols configured by the registry.
66-
pub fn configured_protocols(&self) -> impl Iterator<Item = Cow<str>> {
66+
pub fn configured_protocols(&self) -> impl Iterator<Item = Cow<'_, str>> {
6767
let mut protos: BTreeSet<String> = self.protocol_configs.keys().cloned().collect();
6868
// Backward-compatibility aliases
6969
if self.oci_registry.is_some() || self.oci_namespace_prefix.is_some() {

crates/wasm-pkg-core/src/lock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ impl AsRef<File> for Locker {
364364
}
365365
}
366366

367-
// NOTE(thomastaylor312): These lock file primitives from here on down are mostly copyed wholesale
367+
// NOTE(thomastaylor312): These lock file primitives from here on down are mostly copied wholesale
368368
// from the lock file implementation of cargo-component with some minor modifications to make them
369369
// work with tokio
370370

crates/wasm-pkg-core/src/resolver.rs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,28 @@ pub enum Dependency {
3838
Local(PathBuf),
3939
}
4040

41+
impl std::fmt::Display for Dependency {
42+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
43+
match self {
44+
Dependency::Package(RegistryPackage {
45+
name,
46+
version,
47+
registry,
48+
}) => {
49+
let registry = registry.as_deref().unwrap_or("_");
50+
let name = name.as_ref().map(|n| n.to_string());
51+
52+
write!(
53+
f,
54+
"{{ registry = {registry} package = {}@{version} }}",
55+
name.as_deref().unwrap_or("_:_"),
56+
)
57+
}
58+
Dependency::Local(path_buf) => write!(f, "{}", path_buf.display()),
59+
}
60+
}
61+
}
62+
4163
impl FromStr for Dependency {
4264
type Err = anyhow::Error;
4365

@@ -126,9 +148,9 @@ impl RegistryResolution {
126148
)
127149
.await?;
128150

129-
Ok(tokio_util::io::StreamReader::new(stream.map_err(|e| {
130-
std::io::Error::new(std::io::ErrorKind::Other, e)
131-
})))
151+
Ok(tokio_util::io::StreamReader::new(
152+
stream.map_err(|e| std::io::Error::other(e)),
153+
))
132154
}
133155
}
134156

@@ -181,7 +203,7 @@ impl DependencyResolution {
181203
}
182204

183205
/// Decodes the resolved dependency.
184-
pub async fn decode(&self) -> Result<DecodedDependency> {
206+
pub async fn decode(&self) -> Result<DecodedDependency<'_>> {
185207
// If the dependency path is a directory, assume it contains wit to parse as a package.
186208
let bytes = match self {
187209
DependencyResolution::Local(LocalResolution { path, .. })
@@ -432,7 +454,7 @@ impl<'a> DependencyResolver<'a> {
432454
});
433455

434456
// This is a bit of a hack, but if there are multiple local dependencies that are
435-
// nested and overriden, getting the packages from the local package treats _all_
457+
// nested and overridden, getting the packages from the local package treats _all_
436458
// deps as registry deps. So if we're handling a local path and the dependencies
437459
// have a registry package already, override it. Otherwise follow normal overrides.
438460
// We should definitely fix this and change where we resolve these things

crates/wasm-pkg-core/src/wit.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,16 @@ pub async fn resolve_dependencies(
174174
let mut resolver = DependencyResolver::new_with_client(client, lock_file)?;
175175
// add deps from config first in case they're local deps and then add deps from the directory
176176
if let Some(overrides) = config.overrides.as_ref() {
177-
for (pkg, ovride) in overrides.iter() {
177+
for (pkg, ovr) in overrides.iter() {
178178
let pkg: PackageRef = pkg.parse().context("Unable to parse as a package ref")?;
179-
let dep = match (ovride.path.as_ref(), ovride.version.as_ref()) {
180-
(Some(path), None) => {
181-
let path = tokio::fs::canonicalize(path).await?;
182-
Dependency::Local(path)
183-
}
184-
(Some(path), Some(_)) => {
185-
tracing::warn!("Ignoring version override for local package");
186-
let path = tokio::fs::canonicalize(path).await?;
179+
let dep = match (ovr.path.as_ref(), ovr.version.as_ref()) {
180+
(Some(path), v @ None | v @ Some(_)) => {
181+
if v.is_some() {
182+
tracing::warn!("Ignoring version override for local package");
183+
}
184+
let path = tokio::fs::canonicalize(path)
185+
.await
186+
.with_context(|| format!("{}", path.display()))?;
187187
Dependency::Local(path)
188188
}
189189
(None, Some(version)) => Dependency::Package(RegistryPackage {
@@ -196,9 +196,11 @@ pub async fn resolve_dependencies(
196196
continue;
197197
}
198198
};
199+
tracing::debug!(dependency = ?dep);
199200
resolver
200201
.add_dependency(&pkg, &dep)
201202
.await
203+
.with_context(|| dep.clone())
202204
.context("Unable to add dependency")?;
203205
}
204206
}

crates/wkg/src/oci.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl PushArgs {
171171

172172
fn digest_from_manifest_url(url: &str) -> &str {
173173
url.split('/')
174-
.last()
174+
.next_back()
175175
.expect("url did not contain manifest sha256")
176176
}
177177

crates/wkg/tests/fixtures/wasi-http/wit/types.wit

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ interface types {
205205
/// list with the same key.
206206
entries: func() -> list<tuple<field-key,field-value>>;
207207

208-
/// Make a deep copy of the Fields. Equivelant in behavior to calling the
208+
/// Make a deep copy of the Fields. Equivalent in behavior to calling the
209209
/// `fields` constructor on the return value of `entries`. The resulting
210210
/// `fields` is mutable.
211211
clone: func() -> fields;
@@ -310,7 +310,7 @@ interface types {
310310
/// `delete` operations will fail with `header-error.immutable`.
311311
///
312312
/// This headers resource is a child: it must be dropped before the parent
313-
/// `outgoing-request` is dropped, or its ownership is transfered to
313+
/// `outgoing-request` is dropped, or its ownership is transferred to
314314
/// another component by e.g. `outgoing-handler.handle`.
315315
headers: func() -> headers;
316316
}
@@ -426,19 +426,19 @@ interface types {
426426
finish: static func(this: incoming-body) -> future-trailers;
427427
}
428428

429-
/// Represents a future which may eventaully return trailers, or an error.
429+
/// Represents a future which may eventually return trailers, or an error.
430430
///
431431
/// In the case that the incoming HTTP Request or Response did not have any
432432
/// trailers, this future will resolve to the empty set of trailers once the
433433
/// complete Request or Response body has been received.
434434
resource future-trailers {
435435

436436
/// Returns a pollable which becomes ready when either the trailers have
437-
/// been received, or an error has occured. When this pollable is ready,
437+
/// been received, or an error has occurred. When this pollable is ready,
438438
/// the `get` method will return `some`.
439439
subscribe: func() -> pollable;
440440

441-
/// Returns the contents of the trailers, or an error which occured,
441+
/// Returns the contents of the trailers, or an error which occurred,
442442
/// once the future is ready.
443443
///
444444
/// The outer `option` represents future readiness. Users can wait on this
@@ -450,7 +450,7 @@ interface types {
450450
///
451451
/// The inner `result` represents that either the HTTP Request or Response
452452
/// body, as well as any trailers, were received successfully, or that an
453-
/// error occured receiving them. The optional `trailers` indicates whether
453+
/// error occurred receiving them. The optional `trailers` indicates whether
454454
/// or not trailers were present in the body.
455455
///
456456
/// When some `trailers` are returned by this method, the `trailers`
@@ -483,7 +483,7 @@ interface types {
483483
/// `delete` operations will fail with `header-error.immutable`.
484484
///
485485
/// This headers resource is a child: it must be dropped before the parent
486-
/// `outgoing-request` is dropped, or its ownership is transfered to
486+
/// `outgoing-request` is dropped, or its ownership is transferred to
487487
/// another component by e.g. `outgoing-handler.handle`.
488488
headers: func() -> headers;
489489

@@ -507,7 +507,7 @@ interface types {
507507
///
508508
/// If the user code drops this resource, as opposed to calling the static
509509
/// method `finish`, the implementation should treat the body as incomplete,
510-
/// and that an error has occured. The implementation should propogate this
510+
/// and that an error has occurred. The implementation should propagate this
511511
/// error to the HTTP protocol by whatever means it has available,
512512
/// including: corrupting the body on the wire, aborting the associated
513513
/// Request, or sending a late status code for the Response.
@@ -539,14 +539,14 @@ interface types {
539539
) -> result<_, error-code>;
540540
}
541541

542-
/// Represents a future which may eventaully return an incoming HTTP
542+
/// Represents a future which may eventually return an incoming HTTP
543543
/// Response, or an error.
544544
///
545545
/// This resource is returned by the `wasi:http/outgoing-handler` interface to
546546
/// provide the HTTP Response corresponding to the sent Request.
547547
resource future-incoming-response {
548548
/// Returns a pollable which becomes ready when either the Response has
549-
/// been received, or an error has occured. When this pollable is ready,
549+
/// been received, or an error has occurred. When this pollable is ready,
550550
/// the `get` method will return `some`.
551551
subscribe: func() -> pollable;
552552

@@ -560,8 +560,8 @@ interface types {
560560
/// is `some`, and error on subsequent calls.
561561
///
562562
/// The inner `result` represents that either the incoming HTTP Response
563-
/// status and headers have recieved successfully, or that an error
564-
/// occured. Errors may also occur while consuming the response body,
563+
/// status and headers have received successfully, or that an error
564+
/// occurred. Errors may also occur while consuming the response body,
565565
/// but those will be reported by the `incoming-body` and its
566566
/// `output-stream` child.
567567
get: func() -> option<result<result<incoming-response, error-code>>>;

0 commit comments

Comments
 (0)