Skip to content

fix(minibf): return a JSON error body for a malformed stake address - #1177

Open
michalrus wants to merge 1 commit into
mainfrom
fix/minibf-invalid-stake-addr
Open

fix(minibf): return a JSON error body for a malformed stake address#1177
michalrus wants to merge 1 commit into
mainfrom
fix/minibf-invalid-stake-addr

Conversation

@michalrus

@michalrus michalrus commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Resolves #1178.

Follow-up to:

Problem

The account endpoints resolved the stake address with parse_account_key_param.

For a malformed address, the helper returned a bare http/400 with an empty body.

The real Blockfrost API returns a JSON body with the message "Invalid or malformed stake address format." on every account endpoint.

A blockfrost-tests run found this mismatch on /accounts/{stake_address}/addresses/assets.

Solution

The helper now returns Error::InvalidStakeAddress, so all account endpoints send the correct 400 body.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of invalid stake addresses in account lookups.
    • Requests with malformed stake addresses now return a clear 400 Bad Request response with a specific error message.
    • Standardized error reporting for invalid account credentials.

The account endpoints resolved the stake address with
`parse_account_key_param`. For a malformed address, the helper returned
a bare 400 with an empty body. The real Blockfrost API returns a JSON
body with the message "Invalid or malformed stake address format." on
every account endpoint.

A blockfrost-tests run found this mismatch on
`/accounts/{stake_address}/addresses/assets`.

The helper now returns `Error::InvalidStakeAddress`, so all account
endpoints send the correct 400 body.
@michalrus
michalrus requested review from scarmuega and slowbackspace and a lite review from Copilot August 7, 2026 08:34
@michalrus michalrus self-assigned this Aug 7, 2026
@michalrus michalrus added bug Something isn't working area:minibf Mini Blockfrost (minibf) API labels Aug 7, 2026
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Minibf adds Error::InvalidStakeAddress, maps it to a JSON 400 Bad Request response, and updates account stake-address parsing and routing to use the shared error type. Tests now expect the new error variant.

Changes

Stake address error handling

Layer / File(s) Summary
Stake address error contract
crates/minibf/src/error.rs
Adds Error::InvalidStakeAddress and maps it to a JSON 400 Bad Request response with a stake-address-specific message.
Account route propagation
crates/minibf/src/routes/accounts.rs
Updates stake-address parsing and the by_stake route to return the shared Error type. Malformed credential tests expect Error::InvalidStakeAddress.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

Possibly related PRs

  • txpipe/dolos#1127: Both changes modify stake-address parsing and error handling in crates/minibf/src/routes/accounts.rs.

Suggested reviewers: scarmuega, gonzalezzfelipe

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: returning a JSON error body for malformed stake addresses.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/minibf-invalid-stake-addr

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
crates/minibf/src/routes/accounts.rs (1)

1226-1226: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Verify the public JSON error contract.

The assertion at Line [1226] confirms the internal error variant. The account route tests confirm only StatusCode::BAD_REQUEST. Add one HTTP assertion that parses the response body and checks Invalid or malformed stake address format..

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/minibf/src/routes/accounts.rs` at line 1226, Extend the account route
test around the InvalidStakeAddress case to parse the HTTP response body and
assert it contains the public message “Invalid or malformed stake address
format.”, while retaining the existing internal error assertion and BAD_REQUEST
status check.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@crates/minibf/src/routes/accounts.rs`:
- Line 1226: Extend the account route test around the InvalidStakeAddress case
to parse the HTTP response body and assert it contains the public message
“Invalid or malformed stake address format.”, while retaining the existing
internal error assertion and BAD_REQUEST status check.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: eb7d081b-a216-4d98-bd8b-75cfa2a65d6d

📥 Commits

Reviewing files that changed from the base of the PR and between 608307c and ecb945f.

📒 Files selected for processing (2)
  • crates/minibf/src/error.rs
  • crates/minibf/src/routes/accounts.rs

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR aligns MiniBF’s /accounts/* endpoints with Blockfrost behavior by ensuring malformed stake addresses return a structured JSON 400 error body (instead of an empty-body 400), via a dedicated InvalidStakeAddress error variant.

Changes:

  • Updated parse_account_key_param to return Error::InvalidStakeAddress for malformed stake-address inputs.
  • Switched the /accounts/{stake_address} handler to return Result<_, Error> so it can propagate the new error consistently.
  • Added Error::InvalidStakeAddress with a Blockfrost-matching JSON body/message in IntoResponse.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
crates/minibf/src/routes/accounts.rs Propagates a structured InvalidStakeAddress error from stake-address parsing and updates handler/test expectations.
crates/minibf/src/error.rs Introduces InvalidStakeAddress and maps it to the expected JSON 400 response body.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +67 to +71
Error::InvalidStakeAddress => (
StatusCode::BAD_REQUEST,
Json(ErrorBody::new(
400,
"Bad Request",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think this is a little over the top. 🤨 No Error variant has a JSON body test. The only error-body test in the crate is on PaginationError::InvalidFromTo, which is a different type.

@michalrus
michalrus requested a review from vladimirvolek August 7, 2026 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:minibf Mini Blockfrost (minibf) API bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(minibf): return a JSON error body for a malformed stake address

2 participants