Conversation
ba387f8 to
dce70d8
Compare
dce70d8 to
78a5571
Compare
lann
left a comment
There was a problem hiding this comment.
Only maybe-blocker is question about error handling.
crates/client/src/lib.rs
Outdated
| let namespace_state = op.state.namespace_state(namespace); | ||
| if let Ok(Some(warg_protocol::operator::NamespaceState::Imported { registry })) = | ||
| namespace_state | ||
| { | ||
| return Ok(Some(RegistryDomain::from_str(registry)?)); | ||
| } else if let Ok(Some(warg_protocol::operator::NamespaceState::Defined)) = | ||
| namespace_state | ||
| { | ||
| return Ok(None); | ||
| }; |
There was a problem hiding this comment.
nit: You'd typically use match here:
| let namespace_state = op.state.namespace_state(namespace); | |
| if let Ok(Some(warg_protocol::operator::NamespaceState::Imported { registry })) = | |
| namespace_state | |
| { | |
| return Ok(Some(RegistryDomain::from_str(registry)?)); | |
| } else if let Ok(Some(warg_protocol::operator::NamespaceState::Defined)) = | |
| namespace_state | |
| { | |
| return Ok(None); | |
| }; | |
| match op.state.namespace_state(namespace) { | |
| Ok(Some(warg_protocol::operator::NamespaceState::Imported { registry })) => { | |
| return Ok(Some(RegistryDomain::from_str(registry)?)); | |
| } | |
| Ok(Some(warg_protocol::operator::NamespaceState::Defined)) => { | |
| return Ok(None); | |
| } | |
| _ => (), | |
| } |
crates/client/src/lib.rs
Outdated
| .load_operator(Some(&RegistryDomain::from_str(namespace)?)) | ||
| .await?; | ||
| if let Some(op) = operator { | ||
| let namespace_state = op.state.namespace_state(namespace); |
There was a problem hiding this comment.
Are Errs expected here? Should probably at least log them if not propagating, unless there is a specific reason to completely suppress.
crates/client/src/lib.rs
Outdated
| let namespace_packages = namespaced.get_mut(namespace); | ||
| if let Some(nm_pkgs) = namespace_packages { | ||
| nm_pkgs.push(package); | ||
| } else { | ||
| namespaced.insert(namespace, vec![package]); | ||
| } |
There was a problem hiding this comment.
nit: There is a nice pattern for this:
| let namespace_packages = namespaced.get_mut(namespace); | |
| if let Some(nm_pkgs) = namespace_packages { | |
| nm_pkgs.push(package); | |
| } else { | |
| namespaced.insert(namespace, vec![package]); | |
| } | |
| namespaced.entry(namespace).or_default().push(package); |
src/bin/warg.rs
Outdated
| WargCli::Info(cmd) => cmd.clone().exec().await?, | ||
| WargCli::Key(cmd) => cmd.clone().exec().await?, | ||
| WargCli::Lock(cmd) => { | ||
| with_interactive_retry(|retry: Option<Retry>| async { |
There was a problem hiding this comment.
Can this go outside the match? The commands that don't support retry shouldn't be returning this error anyway and can just ignore the retry variable?
f18c53b to
00819c6
Compare
| match op.state.namespace_state(namespace) { | ||
| Ok(Some(warg_protocol::operator::NamespaceState::Imported { registry })) => { | ||
| return Ok(Some(RegistryDomain::from_str(registry)?)); | ||
| } | ||
| Ok(Some(warg_protocol::operator::NamespaceState::Defined)) => { | ||
| return Ok(None); | ||
| } | ||
| Ok(None) => return Ok(None), | ||
| Err(e) => { | ||
| return Err(ClientError::SimilarNamespace { | ||
| namespace: namespace.to_string(), | ||
| e: e.to_string(), | ||
| }); | ||
| } | ||
| } |
There was a problem hiding this comment.
minor: its difficult to see that this if block always returns
| match op.state.namespace_state(namespace) { | |
| Ok(Some(warg_protocol::operator::NamespaceState::Imported { registry })) => { | |
| return Ok(Some(RegistryDomain::from_str(registry)?)); | |
| } | |
| Ok(Some(warg_protocol::operator::NamespaceState::Defined)) => { | |
| return Ok(None); | |
| } | |
| Ok(None) => return Ok(None), | |
| Err(e) => { | |
| return Err(ClientError::SimilarNamespace { | |
| namespace: namespace.to_string(), | |
| e: e.to_string(), | |
| }); | |
| } | |
| } | |
| return match op.state.namespace_state(namespace) { | |
| Ok(Some(warg_protocol::operator::NamespaceState::Imported { registry })) => { | |
| Ok(Some(RegistryDomain::from_str(registry)?)) | |
| } | |
| Ok(Some(warg_protocol::operator::NamespaceState::Defined)) => { | |
| Ok(None) | |
| } | |
| Ok(None) => return Ok(None), | |
| Err(e) => { | |
| Err(ClientError::SimilarNamespace { | |
| namespace: namespace.to_string(), | |
| e: e.to_string(), | |
| }) | |
| } | |
| } |
| #[derive(Debug, Error)] | ||
| pub enum ClientError { | ||
| /// Similar Namespace | ||
| #[error("Namespace `{namespace}` not found in operator log but found namespace `{e}`, which has alternative casing.")] |
There was a problem hiding this comment.
Are we not enforcing lowercase namespaces? I think we should be... WebAssembly/component-model#338
There was a problem hiding this comment.
Yeah, that is outstanding. Probably better as a separate PR. Found the open issue #245
crates/client/src/lib.rs
Outdated
| /// Interactively retry when hint header received from warg server | ||
| pub async fn with_interactive_retry<F>(f: impl Fn(Option<Retry>) -> F) -> Result<()> | ||
| where | ||
| F: Future<Output = Result<()>>, | ||
| { | ||
| f(None).await?; | ||
| Ok(()) | ||
| } |
There was a problem hiding this comment.
This doesn't appear to do what it claims to do?
Rather than updating the state at the beginning of a client interaction to use a specific url, the client expects to check the namespace storage for a url and pass it as an arg, better enabling consumers to fetch packages across multiple namespaces.
There is also updated logic for encouraging standard ways of retrying with
Warg-Hint-Headerresponses from the registry after using the hint to update local namespace mappings.