Skip to content

fix: return preflight simulation errors as 400 instead of 500#49

Merged
findolor merged 1 commit intomainfrom
fix/preflight-error-handling
Feb 27, 2026
Merged

fix: return preflight simulation errors as 400 instead of 500#49
findolor merged 1 commit intomainfrom
fix/preflight-error-handling

Conversation

@findolor
Copy link
Collaborator

@findolor findolor commented Feb 24, 2026

Motivation

When a swap calldata request fails due to a preflight simulation error (e.g. "ERC20: transfer amount exceeds balance"), the API returns a generic 500 Internal Server Error with "failed to generate calldata". This hides the actual cause from callers and makes it look like a server bug when it's really an on-chain condition the user can act on.

Solution

  • Add explicit match arm for RaindexError::PreflightError in map_raindex_error() so it returns a 400 Bad Request with the readable error message instead of falling through to the catch-all 500 Internal Error.
  • Export COMMIT_SHA automatically in the nix dev shell (flake.nix) so local builds no longer require manually setting the env var.
  • Add dev-config.toml for local development and gitignore docs/book/ build output.

Checks

By submitting this for review, I'm confirming I've done the following:

  • made this PR as small as possible
  • unit-tested any new functionality
  • linked any relevant issues or PRs
  • included screenshots (if this involves a front-end change)

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Enhanced error handling for preflight validation failures with improved, user-friendly diagnostic messages. Users now receive clearer feedback when validation checks fail.
  • Chores

    • Added development configuration file with settings for logging, database connectivity, and external registry endpoints.
    • Updated development environment setup to automatically include build metadata and commit tracking information.

PreflightError (e.g. "ERC20: transfer amount exceeds balance") was
falling through to the catch-all arm in map_raindex_error and being
returned as a 500 Internal Error with a generic message. Now it is
explicitly matched and returned as a 400 Bad Request with the
readable error message so callers know why their swap failed.

Also export COMMIT_SHA automatically in the nix dev shell so local
cargo builds no longer need the env var set manually.

Add dev-config.toml and gitignore docs/book/ build output.
@findolor findolor self-assigned this Feb 24, 2026
@findolor findolor requested a review from hardyjosh February 24, 2026 12:34
@coderabbitai
Copy link

coderabbitai bot commented Feb 24, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d773fed and 706b878.

📒 Files selected for processing (4)
  • .gitignore
  • dev-config.toml
  • flake.nix
  • src/routes/swap/mod.rs

📝 Walkthrough

Walkthrough

The changes introduce development configuration, update the Nix development shell, and extend error handling. A new dev configuration file is added with paths and rate limits, the shell environment is modified to include a COMMIT_SHA variable derived from Git HEAD, error handling for preflight validation failures is added to the swap route, and the gitignore is updated to exclude documentation build artifacts.

Changes

Cohort / File(s) Summary
Configuration & Documentation
.gitignore, dev-config.toml
Added gitignore entry for docs/book/ and introduced new development configuration file with settings for logging directory, SQLite database URL, registry URL, rate limits, and documentation directory.
Build Environment
flake.nix
Modified devShells.default to explicitly define shellHook, extending the base rainix shellHook with a COMMIT_SHA environment variable set to Git HEAD or "dev" as fallback.
Error Handling
src/routes/swap/mod.rs
Extended map_raindex_error to handle RaindexError::PreflightError by logging a warning and returning ApiError::BadRequest with the error's readable message.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 Hops in with glee 🌿
Config files align, docs are tucked away,
COMMIT_SHA now tracks the way,
Preflight errors caught and styled so neat—
Development paths are complete! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: fixing error handling to return 400 instead of 500 for preflight simulation errors, which aligns with the primary code change in src/routes/swap/mod.rs.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/preflight-error-handling

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 and usage tips.

@findolor findolor merged commit 0468a1c into main Feb 27, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants