-
Notifications
You must be signed in to change notification settings - Fork 12
Verification + refactoring with preparations to generalization #202
Conversation
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.
LGTM!
|
||
[[bin]] | ||
name = "verify" | ||
version = "0.0.1" |
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.
Nitpick: conventionally, the first version is 0.1.0 https://semver.org/#how-should-i-deal-with-revisions-in-the-0yz-initial-development-phase. But it is only a convention :)
And the version can be set at a workspace level, e.g.
https://github.com/NethermindEth/dydx-v4-rust/blob/trunk/Cargo.toml and
https://github.com/NethermindEth/dydx-v4-rust/blob/trunk/client/Cargo.toml
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.
0.1.0 makes sense.
And the version can be set at a workspace level, e.g.
I'm afraid release cycle for components won't be the same
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.
Done
PutItemError::ConditionalCheckFailedException(_) => { | ||
error!("Reverification attempt, id: {}", request.id); | ||
let response = lambda_http::Response::builder() | ||
.status(400) |
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.
Nitpick: perhaps, it is worth to use a designated const for readability
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.
All of them were replaced here. Child branch tho
} | ||
_ => return Err(Box::new(SdkError::ServiceError(val)).into()), | ||
}, | ||
Err(err) => return Err(Box::new(err).into()), |
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.
Nitpick: probably, error handling would be more ergonomic with anyhow
crate?
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.
Done here
.await | ||
.map_err(Box::new)?; | ||
|
||
if let None = &objects.contents { |
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.
Nitpick: more idiomatic
objects.contents.as_ref().ok_or_else(|| {...})?;
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.
Done here
#[derive(thiserror::Error, Debug)] | ||
pub enum ItemError { | ||
#[error("Invalid Item format: {0}")] | ||
FormatError(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.
Nitpick: FormatError
can wrap anyhow::Error
(https://github.com/dtolnay/thiserror). In this case it would be more ergonomic to use with anyhow
macros
@@ -66,8 +78,19 @@ pub async fn do_compile( | |||
let hardhat_config_content = hardhat_config_builder.build().to_string_config(); | |||
|
|||
// create parent directories | |||
tokio::fs::create_dir_all(hardhat_config_path.parent().unwrap()).await?; | |||
tokio::fs::write(hardhat_config_path, hardhat_config_content).await?; | |||
tokio::fs::create_dir_all(hardhat_config_path.parent().unwrap()) |
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 we raise an Error
(with ?
) here instead of panicking?
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.
Done here
.to_string_config(); | ||
|
||
// create parent directories | ||
tokio::fs::create_dir_all(hardhat_config_path.parent().unwrap()) |
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.
Could we return early an Error
(with ?
) here instead of unwrap
?
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.
Done here
}; | ||
|
||
let mut file_keys = Vec::with_capacity(compilation_output.artifacts_data.len()); | ||
for el in compilation_output.artifacts_data { |
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.
Could we upload files concurrently?
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.
Done here
|
||
let mut presigned_urls = Vec::with_capacity(file_keys.len()); | ||
for el in file_keys { | ||
let expires_in = PresigningConfig::expires_in(DOWNLOAD_URL_EXPIRATION).unwrap(); |
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.
early error return with ?
?
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.
It's just never fails with current implementation. If it does in case dependancies change, then we would fail all the time here anyway.
pub fn build(self) -> Result<PresigningConfig, PresigningConfigError> {
let expires_in = self.expires_in.ok_or(ErrorKind::ExpiresInRequired)?;
if expires_in > ONE_WEEK {
return Err(ErrorKind::ExpiresInDurationTooLong.into());
}
Ok(PresigningConfig {
start_time: self.start_time.unwrap_or_else(
// This usage is OK—customers can easily override this.
#[allow(clippy::disallowed_methods)]
SystemTime::now,
),
expires_in,
})
}
let mut presigned_urls = Vec::with_capacity(file_keys.len()); | ||
for el in file_keys { | ||
let expires_in = PresigningConfig::expires_in(DOWNLOAD_URL_EXPIRATION).unwrap(); | ||
let presigned_request = self |
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.
Could we make requests concurrently?
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.
Done here
})?; | ||
tokio::fs::create_dir_all(&artifacts_path) | ||
.await | ||
.map_err(anyhow::Error::from) |
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.
Why do we use the anyhow::Error::from
, can't we just implement From<...>
for our CompilationError
?
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.
Noticed that can be with_context, it wraps to anyhow automatically.
with regards to:
Why do we use the anyhow::Error::from, can't we just implement From<...> for our CompilationError?
Not done this way since while every anyhow::Error is CompilationError::UnknownError, not every io::Error is CompilationError::UnknownError
209a387
to
5550912
Compare
5550912
to
3bf7319
Compare
#204
The main idea behind the refactoring is to prepare for the future extraction of main components into a separate library. The following components may roughly be noticed already.