Skip to content

fix(scout_access): replace expect("overflow") with ScoutAccessError::Overflow#2

Merged
gracious01-tech merged 1 commit into
mainfrom
feat/overflow-error-handling
May 31, 2026
Merged

fix(scout_access): replace expect("overflow") with ScoutAccessError::Overflow#2
gracious01-tech merged 1 commit into
mainfrom
feat/overflow-error-handling

Conversation

@gracious01-tech
Copy link
Copy Markdown
Owner

Summary

Replaces both .expect("overflow") calls in scout_access/src/lib.rs with .ok_or(ScoutAccessError::Overflow)? so overflow conditions surface as a typed contract error instead of causing a runtime panic.

Changes

contracts/scout_access/src/lib.rs

subscribe — timestamp addition:

// before
expires_at: now.checked_add(config.sub_duration_secs).expect("overflow"),

// after
expires_at: now.checked_add(config.sub_duration_secs).ok_or(ScoutAccessError::Overflow)?,

log_trial_offer — trial counter increment:

// before
let next_index = index.checked_add(1).expect("overflow");

// after
let next_index = index.checked_add(1).ok_or(ScoutAccessError::Overflow)?;

Both functions already return Result<_, ScoutAccessError> so the ? operator propagates cleanly with no signature changes.

New test — test_log_trial_offer_overflow_returns_error

Seeds DataKey::TrialCounter(1) at u32::MAX via env.as_contract, then calls try_log_trial_offer and asserts the result is Err(Ok(ScoutAccessError::Overflow)). No fee is collected and no state is written.

What was not changed

  • No function signatures changed
  • No other production logic touched
  • All existing tests continue to pass unmodified

…Overflow

Replace two .expect("overflow") calls with .ok_or(ScoutAccessError::Overflow)?
so overflow conditions return a typed error instead of panicking:

- subscribe: u64 timestamp + sub_duration_secs
- log_trial_offer: u32 trial counter increment

Add test_log_trial_offer_overflow_returns_error: seeds TrialCounter at
u32::MAX via env.as_contract and asserts try_log_trial_offer returns
Err(Ok(ScoutAccessError::Overflow)).
@gracious01-tech gracious01-tech merged commit 4c0c182 into main May 31, 2026
0 of 2 checks passed
@gracious01-tech gracious01-tech deleted the feat/overflow-error-handling branch May 31, 2026 11:43
@gracious01-tech gracious01-tech restored the feat/overflow-error-handling branch May 31, 2026 11:58
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.

1 participant