Skip to content

Fix/deterministic error ordering#714

Open
afurious wants to merge 5 commits intoJagadeeshftw:masterfrom
afurious:fix/deterministic-error-ordering
Open

Fix/deterministic error ordering#714
afurious wants to merge 5 commits intoJagadeeshftw:masterfrom
afurious:fix/deterministic-error-ordering

Conversation

@afurious
Copy link

closes #612
#612 Ensure Deterministic Error Ordering and Prioritization

…applications handlers

- Define clear validation precedence hierarchy for all handlers
- Reorder validation checks to follow consistent priority:
  1. Service Availability (db, config)
  2. Input Format Validation (params parsing)
  3. Authentication (user verification)
  4. Request Body Validation (payload checks)
  5. External Account Linking (GitHub account)
  6. Resource Existence (project/issue lookup)
  7. Database/Internal Errors (unexpected failures)
  8. Authorization (permission checks)
  9. Business Logic Constraints (business rules)
  10. External Service Errors (GitHub API)

- Apply() handler: Reordered to check service → input → auth → body → linking → existence → business logic
- PostBotComment() handler: Reordered to separate existence, internal errors, authorization, and business logic
- Withdraw() handler: Reordered to check existence before authorization, separate internal errors
- Assign() handler: Reordered to separate existence, internal errors, authorization, and business logic
- Unassign() handler: Reordered to separate existence, internal errors, authorization, and business logic
- Reject() handler: Reordered to separate existence, internal errors, authorization, and business logic

This change improves debuggability and predictability by ensuring the same
inputs always produce the same error, regardless of execution path.
- Define 11-level error precedence hierarchy in ERROR_PRECEDENCE.md
- Document error priority for all contract error codes
- Reorder validation checks in bounty_escrow contract functions:
  * lock_funds: Pause → Init → Auth → State conflicts → Business logic
  * release_funds: Pause → Init → Auth → Existence → State conflicts → Resource state
  * release_with_capability: Pause → Existence → State → Capability → Business logic → Availability
- Add comprehensive error precedence tests covering multi-error scenarios:
  * test_precedence_paused_over_not_initialized
  * test_precedence_not_initialized_over_bounty_exists
  * test_precedence_bounty_exists_over_amount_validation
  * test_precedence_not_found_over_invalid_state
  * test_precedence_claim_pending_over_invalid_state
  * test_precedence_invalid_state_over_invalid_amount
  * test_precedence_invalid_amount_over_insufficient_funds
  * test_precedence_amount_below_minimum_checked_in_order
  * test_precedence_amount_above_maximum_checked_in_order
  * test_precedence_comprehensive_lock_funds
  * test_precedence_comprehensive_release_funds
- Ensure consistent validation pattern across all entry points

This change improves debuggability and predictability by ensuring the same
inputs always produce the same error, regardless of contract version.
Resolved conflicts in contracts/bounty_escrow/contracts/escrow/src/lib.rs:
- Combined test module imports (test_risk_flags + error_precedence_tests)
- Integrated deterministic error ordering in lock_funds and release_funds
- Maintained proper error priority checks from both branches
@vercel
Copy link

vercel bot commented Feb 27, 2026

@afurious is attempting to deploy a commit to the Jagadeesh B's projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

Ensure Deterministic Error Ordering and Prioritization

1 participant