Skip to content

chore: improve error handling #243

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

Merged
merged 5 commits into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ pub struct Args {

impl Args {
pub async fn run(self) -> eyre::Result<()> {
rustls::crypto::ring::default_provider()
.install_default()
.expect("Failed to install TLS ring CryptoProvider");
let _ = rustls::crypto::ring::default_provider().install_default();

let debug_addr = format!("{}:{}", self.debug_host, self.debug_server_port);

Expand All @@ -103,7 +101,7 @@ impl Args {
Commands::Debug { command } => match command {
DebugCommands::SetExecutionMode { execution_mode } => {
let client = DebugClient::new(debug_addr.as_str())?;
let result = client.set_execution_mode(execution_mode).await.unwrap();
let result = client.set_execution_mode(execution_mode).await?;
println!("Response: {:?}", result.execution_mode);

Ok(())
Expand Down
6 changes: 3 additions & 3 deletions src/client/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ pub fn secret_to_bearer_header(secret: &JwtSecret) -> HeaderValue {
.encode(&Claims {
iat: SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.expect("Failed to get epoch time")
.as_secs(),
exp: None,
})
.unwrap()
.expect("Failed to encode JWT claims")
)
.parse()
.unwrap()
.expect("Failed to parse JWT Header")
}
5 changes: 3 additions & 2 deletions src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ async fn init_metrics_server(addr: SocketAddr, handle: PrometheusHandle) -> eyre
"/metrics" => Response::builder()
.header("content-type", "text/plain")
.body(HttpBody::from(handle.render()))
.unwrap(),
.expect("Failed to create metrics response"),
_ => Response::builder()
.status(StatusCode::NOT_FOUND)
.body(HttpBody::empty())
.unwrap(),
.expect("Failed to create not found response"),
};

async { Ok::<_, hyper::Error>(response) }
});

Expand Down
6 changes: 3 additions & 3 deletions src/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,19 @@ fn ok() -> HttpResponse<HttpBody> {
HttpResponse::builder()
.status(200)
.body(HttpBody::from("OK"))
.unwrap()
.expect("Failed to create OK reponse")
}

fn partial_content() -> HttpResponse<HttpBody> {
HttpResponse::builder()
.status(206)
.body(HttpBody::from("Partial Content"))
.unwrap()
.expect("Failed to create partial content response")
}

fn service_unavailable() -> HttpResponse<HttpBody> {
HttpResponse::builder()
.status(503)
.body(HttpBody::from("Service Unavailable"))
.unwrap()
.expect("Failed to create service unavailable response")
}
9 changes: 5 additions & 4 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use alloy_rpc_types_engine::{
};
use alloy_rpc_types_eth::BlockNumberOrTag;
use bytes::BytesMut;
use eyre::{Context, ContextCompat};
use futures::FutureExt;
use futures::future::BoxFuture;
use jsonrpsee::http_client::{HttpClient, transport::HttpBackend};
Expand Down Expand Up @@ -82,7 +83,7 @@ impl EngineApi {
let client = jsonrpsee::http_client::HttpClientBuilder::default()
.set_http_middleware(middleware)
.build(url)
.expect("Failed to create http client");
.context("Failed to create http client")?;

Ok(Self {
engine_api_client: client,
Expand Down Expand Up @@ -411,7 +412,7 @@ impl SimpleBlockGenerator {

/// Initialize the block generator by fetching the latest block
pub async fn init(&mut self) -> eyre::Result<()> {
let latest_block = self.engine_api.latest().await?.expect("block not found");
let latest_block = self.engine_api.latest().await?.context("block not found")?;
self.latest_hash = latest_block.header.hash;
self.timestamp = latest_block.header.timestamp;
Ok(())
Expand Down Expand Up @@ -470,7 +471,7 @@ impl SimpleBlockGenerator {
)
.await?;

let payload_id = result.payload_id.expect("missing payload id");
let payload_id = result.payload_id.context("missing payload id")?;

if !empty_blocks {
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
Expand Down Expand Up @@ -505,7 +506,7 @@ impl SimpleBlockGenerator {
.validator
.get_block_creator(new_block_hash)
.await?
.expect("block creator not found");
.context("block creator not found")?;

Ok((new_block_hash, block_creator))
}
Expand Down
Loading