Skip to content

feat: Inconsistent Error Handling and Missing Error Messages #199

@KevinMB0220

Description

@KevinMB0220

Issue: Inconsistent Error Handling and Missing Error Messages

Problem: The contract lacks proper error handling and meaningful error messages:

  • No custom error definitions in the main contract
  • Functions can panic with generic Cairo errors
  • No validation for invalid input parameters (e.g., negative damage amounts)
  • Missing error handling for edge cases

Location: contract/src/systems/game.cairo:1-139

Problematic code:

fn take_damage(ref self: ContractState, amount: u32) {
    // No validation for amount > 0
    // No validation for amount overflow
    PlayerTrait::take_damage(ref player, amount.try_into().unwrap()); // Can panic
}

Impact:

  • Poor debugging experience
  • Unclear error messages for users
  • Potential panic conditions not handled
  • Difficult to maintain and troubleshoot

Suggested solution:

  • Add error module with custom error constants
  • Implement input validation for all functions
  • Replace unwrap() with proper error handling
  • Add meaningful error messages for all failure cases

Metadata

Metadata

Labels

CairoSomething isn't workingonlydust-waveContribute to awesome OSS repos during OnlyDust's open source week

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions