Skip to content
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

Verification + refactoring with preparations to generalization #202

Merged
merged 13 commits into from
Oct 18, 2024

Conversation

taco-paco
Copy link
Contributor

@taco-paco taco-paco commented Sep 26, 2024

#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.

pub trait MessageProcessor {
    type Message;
    async fn process_message(&self, message: Self::Message) -> impl Into<TaskResult>;
}
pub trait InputPreparator {
     type Request;
     type Output;
     async fn prepare_input(&self, request: &Self::Request) -> Result<Self::Output>;
}
pub trait MessageValidator {
     type Message;
     async fn validate(&self, message: &Self::Message) -> Result<()>
}

Copy link

@maksimryndin maksimryndin left a 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"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@taco-paco taco-paco Oct 17, 2024

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

Copy link
Contributor Author

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)

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

Copy link
Contributor Author

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()),

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?

Copy link
Contributor Author

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 {

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(|| {...})?;

Copy link
Contributor Author

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),

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())

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?

Copy link
Contributor Author

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())

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?

Copy link
Contributor Author

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 {

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?

Copy link
Contributor Author

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();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

early error return with ??

Copy link
Contributor Author

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

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?

Copy link
Contributor Author

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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

@taco-paco taco-paco changed the base branch from feat/horizontal/retriable-client to feat/horizontal/main October 18, 2024 12:48
@taco-paco taco-paco merged commit b87a0dd into feat/horizontal/main Oct 18, 2024
2 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

3 participants