From 9dc18a670aa6112db068b01ceb95f7ee0520fd79 Mon Sep 17 00:00:00 2001 From: segfault-magnet Date: Tue, 20 Aug 2024 19:02:27 +0200 Subject: [PATCH 1/2] add context to errors --- committer/src/errors.rs | 28 ++++++++++++++++++++++++++++ committer/src/main.rs | 19 +++++++++++++------ 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/committer/src/errors.rs b/committer/src/errors.rs index 4f989a48..525369fd 100644 --- a/committer/src/errors.rs +++ b/committer/src/errors.rs @@ -1,3 +1,5 @@ +use std::fmt::Display; + use actix_web::ResponseError; use tokio::task::JoinError; @@ -11,6 +13,13 @@ pub enum Error { Storage(String), } +pub trait WithContext { + fn with_context(self, context: F) -> Result + where + C: Display + Send + Sync + 'static, + F: FnOnce() -> C; +} + impl From for Error { fn from(error: serde_json::Error) -> Self { Self::Other(error.to_string()) @@ -71,3 +80,22 @@ impl From for Error { impl ResponseError for Error {} pub type Result = std::result::Result; + +impl WithContext for Result { + fn with_context(self, context: F) -> Result + where + C: Display + Send + Sync + 'static, + F: FnOnce() -> C, + { + if let Err(err) = self { + let new_err = match err { + Error::Other(e) => Error::Other(format!("{}: {}", context(), e)), + Error::Network(e) => Error::Network(format!("{}: {}", context(), e)), + Error::Storage(e) => Error::Storage(format!("{}: {}", context(), e)), + }; + Err(new_err) + } else { + self + } + } +} diff --git a/committer/src/main.rs b/committer/src/main.rs index 1441021c..61c36e00 100644 --- a/committer/src/main.rs +++ b/committer/src/main.rs @@ -5,7 +5,7 @@ mod errors; mod setup; use api::launch_api_server; -use errors::Result; +use errors::{Result, WithContext}; use metrics::prometheus::Registry; use tokio_util::sync::CancellationToken; @@ -21,10 +21,14 @@ pub type Validator = validator::BlockValidator; async fn main() -> Result<()> { setup::logger(); - let config = config::parse()?; - config.validate()?; + let config = config::parse().with_context(|| "failed to parse config")?; + config + .validate() + .with_context(|| "config validation failed")?; - let storage = setup::storage(&config).await?; + let storage = setup::storage(&config) + .await + .with_context(|| "failed to connect to database")?; let internal_config = config::Internal::default(); let cancel_token = CancellationToken::new(); @@ -35,7 +39,9 @@ async fn main() -> Result<()> { setup::fuel_adapter(&config, &internal_config, &metrics_registry); let (ethereum_rpc, eth_health_check) = - setup::l1_adapter(&config, &internal_config, &metrics_registry).await?; + setup::l1_adapter(&config, &internal_config, &metrics_registry) + .await + .with_context(|| "could not setup l1 adapter")?; let commit_interval = ethereum_rpc.commit_interval(); @@ -104,7 +110,8 @@ async fn main() -> Result<()> { fuel_health_check, eth_health_check, ) - .await?; + .await + .with_context(|| "api server")?; shut_down(cancel_token, handles, storage).await } From 5480742f758c041f4a5d236179b4ba36f0e418d3 Mon Sep 17 00:00:00 2001 From: segfault-magnet Date: Tue, 20 Aug 2024 19:19:35 +0200 Subject: [PATCH 2/2] use ubuntu-latest since other runner is busy --- .github/workflows/ci.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 24b1e104..d69703df 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ env: jobs: verify-rust-version: - runs-on: buildjet-4vcpu-ubuntu-2204 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 # Ensure CI is using the same minimum toolchain specified in fuels Cargo.toml @@ -49,7 +49,7 @@ jobs: cargo-verifications: needs: - verify-rust-version - runs-on: buildjet-4vcpu-ubuntu-2204 + runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v3 @@ -79,7 +79,7 @@ jobs: run: ./run_tests.sh publish-crates-check: - runs-on: buildjet-4vcpu-ubuntu-2204 + runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v3 @@ -101,7 +101,7 @@ jobs: - publish-crates-check # Only do this job if publishing a release if: github.event_name == 'release' && github.event.action == 'published' - runs-on: buildjet-4vcpu-ubuntu-2204 + runs-on: ubuntu-latest steps: - name: Checkout repository @@ -125,7 +125,7 @@ jobs: publish-docker-image: needs: - cargo-verifications - runs-on: buildjet-4vcpu-ubuntu-2204 + runs-on: ubuntu-latest permissions: contents: read packages: write