-
Notifications
You must be signed in to change notification settings - Fork 30
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
make better use of namespace storage #263
Conversation
ba387f8
to
dce70d8
Compare
dce70d8
to
78a5571
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are Err
s 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
crates/client/src/lib.rs
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: its difficult to see that this if
block always return
s
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(), | |
}) | |
} | |
} |
@@ -995,6 +1059,15 @@ pub struct PackageDownload { | |||
/// Represents an error returned by Warg registry clients. | |||
#[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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we not enforcing lowercase namespaces? I think we should be... WebAssembly/component-model#338
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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-Header
responses from the registry after using the hint to update local namespace mappings.