All bare panic!() calls have been replaced with stable Error variants, ensuring every failure path maps to a well-defined error code.
File: src/err.rs
- New Variant:
GasBudgetExceeded = 417 - Location: General Errors category (400-418)
- Description: "Gas budget cap has been exceeded for the operation."
File: src/lib.rs
Before:
let stored_admin: Address = env
.storage()
.persistent()
.get(&Symbol::new(&env, "Admin"))
.unwrap_or_else(|| {
panic!("Admin not set"); // ❌ Bare panic
});After:
let stored_admin: Address = match env
.storage()
.persistent()
.get(&Symbol::new(&env, "Admin"))
{
Some(admin_addr) => admin_addr,
None => panic_with_error!(env, Error::AdminNotSet), // ✅ Maps to Error::AdminNotSet
};Before:
let stored_admin: Address = env
.storage()
.persistent()
.get(&Symbol::new(&env, "Admin"))
.unwrap_or_else(|| {
panic!("Admin not set"); // ❌ Bare panic
});After:
let stored_admin: Address = match env
.storage()
.persistent()
.get(&Symbol::new(&env, "Admin"))
{
Some(admin_addr) => admin_addr,
None => panic_with_error!(env, Error::AdminNotSet), // ✅ Maps to Error::AdminNotSet
};File: src/gas.rs
Before:
if let Some(limit) = Self::get_limit(env, operation) {
if actual_cost > limit {
panic!("Gas budget cap exceeded"); // ❌ Bare panic
}
}After:
if let Some(limit) = Self::get_limit(env, operation) {
if actual_cost > limit {
panic_with_error!(env, crate::err::Error::GasBudgetExceeded); // ✅ Maps to Error::GasBudgetExceeded
}
}| Failure Path | Previous | Now | Error Code |
|---|---|---|---|
| Admin not configured | panic!("Admin not set") |
Error::AdminNotSet |
418 |
| Gas budget exceeded | panic!("Gas budget cap exceeded") |
Error::GasBudgetExceeded |
417 |
- Stable Error Codes: All failures now map to defined error variants with unique numeric codes (417, 418)
- Better Diagnostics: Contract clients can now handle these errors programmatically instead of unexpected panics
- Improved Reliability: Error variants have associated metadata (severity, recovery strategy, messages)
- Contract Compatibility: Clients and integrations can safely decode these error codes
- ✅ All bare
panic!()calls related to failure paths have been identified and replaced - ✅ New error variant added to the error enum with proper documentation
- ✅ Both locations using Admin checks now use standardized error handling
- ✅ Gas tracking operations now report errors instead of panicking
- ✅ Pattern follows existing codebase conventions (
panic_with_error!macro)
See ERROR_HANDLING_ANALYSIS.md for complete error handling analysis and best practices.