From b3aec6fafa0ba9ab65ad40de020acea74fe1df40 Mon Sep 17 00:00:00 2001 From: Supanat Potiwarakorn Date: Wed, 20 Sep 2023 15:45:59 +0700 Subject: [PATCH] [FIX-16] Single occurrence of unsafe error handling --- contracts/transmuter/src/limiter/limiters.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/contracts/transmuter/src/limiter/limiters.rs b/contracts/transmuter/src/limiter/limiters.rs index 4dfa133..0d81fbd 100644 --- a/contracts/transmuter/src/limiter/limiters.rs +++ b/contracts/transmuter/src/limiter/limiters.rs @@ -1,5 +1,5 @@ use cosmwasm_schema::cw_serde; -use cosmwasm_std::{ensure, Decimal, Storage, Timestamp, Uint64}; +use cosmwasm_std::{ensure, Decimal, StdError, Storage, Timestamp, Uint64}; use cw_storage_plus::Map; use crate::ContractError; @@ -166,7 +166,10 @@ impl ChangeLimiter { } else { // If the division is over, create a new division let mut divisions = updated_limiter.divisions; - let latest_division = divisions.last().expect("divisions must not be empty"); + let latest_division = divisions + .last() + // this error should never occur since we checked if divisions is empty + .ok_or(StdError::generic_err("divisions must not be empty"))?; if latest_division.elapsed_time(block_time)? >= division_size { let started_at = latest_division.next_started_at(division_size, block_time)?;