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

chore: use more specific error types #521

Merged
merged 2 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 3 additions & 3 deletions bolt-sidecar/src/api/commitments/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ pub async fn rpc_entrypoint(
};

// Parse the inclusion request from the parameters
let mut inclusion_request: InclusionRequest = serde_json::from_value(request_json)
.map_err(|e| RejectionError::ValidationFailed(e.to_string()))
.inspect_err(|e| error!("Failed to parse inclusion request: {:?}", e))?;
let mut inclusion_request = serde_json::from_value::<InclusionRequest>(request_json)
.map_err(RejectionError::Json)
.inspect_err(|err| error!(?err, "Failed to parse inclusion request"))?;

debug!(?inclusion_request, "New inclusion request");

Expand Down
11 changes: 11 additions & 0 deletions bolt-sidecar/src/api/commitments/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ pub enum CommitmentError {
/// Duplicate request.
#[error("Duplicate request")]
Duplicate,
/// No available public key to sign commitment request with for a given slot.
#[error("No available public key to sign request with (slot {0})")]
NoAvailablePubkeyForSlot(u64),
merklefruit marked this conversation as resolved.
Show resolved Hide resolved
/// Internal server error.
#[error("Internal server error")]
Internal,
Expand Down Expand Up @@ -73,6 +76,11 @@ impl IntoResponse for CommitmentError {
Json(JsonResponse::from_error(-32002, self.to_string())),
)
.into_response(),
Self::NoAvailablePubkeyForSlot(_) => (
StatusCode::INTERNAL_SERVER_ERROR,
Json(JsonResponse::from_error(-32008, self.to_string())),
)
.into_response(),
Self::NoSignature => {
(StatusCode::BAD_REQUEST, Json(JsonResponse::from_error(-32003, self.to_string())))
.into_response()
Expand Down Expand Up @@ -117,6 +125,9 @@ pub enum RejectionError {
/// State validation failed for this request.
#[error("Validation failed: {0}")]
ValidationFailed(String),
/// JSON parsing error.
#[error("JSON parsing error: {0}")]
Json(#[from] serde_json::Error),
}

/// Implements the commitments-API: <https://chainbound.github.io/bolt-docs/api/rpc>
Expand Down
2 changes: 1 addition & 1 deletion bolt-sidecar/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ impl<C: StateFetcher, ECDSA: SignerECDSA> SidecarDriver<C, ECDSA> {
self.constraints_client.find_signing_key(validator_pubkey, available_pubkeys)
else {
error!(%target_slot, "No available public key to sign constraints with");
let _ = response.send(Err(CommitmentError::Internal));
let _ = response.send(Err(CommitmentError::NoAvailablePubkeyForSlot(target_slot)));
return;
};

Expand Down
Loading