Skip to content

Replace .expect panic with Error::NotInitialized return in get_admin#2071

Open
Meet-hybrid wants to merge 6 commits into
EarnQuestOne:mainfrom
Meet-hybrid:fix/not-initialized-error
Open

Replace .expect panic with Error::NotInitialized return in get_admin#2071
Meet-hybrid wants to merge 6 commits into
EarnQuestOne:mainfrom
Meet-hybrid:fix/not-initialized-error

Conversation

@Meet-hybrid

Copy link
Copy Markdown
Contributor

Description
This PR improves error handling in src/storage.rs by replacing the .expect("Contract not initialized") panic with a proper Error::NotInitialized return. This aligns with the contract’s existing Result<_, Error> error model and ensures consistent, graceful failure handling.

Changes Introduced
Added/confirmed NotInitialized variant in errors.rs.

Replaced .expect("Contract not initialized") with ok_or(Error::NotInitialized)? (or equivalent).

Implemented a test case that invokes an entrypoint before initialization and asserts a graceful error return instead of a panic.

Files Affected
src/storage.rs

src/errors.rs

tests/ (new test for uninitialized state)

Acceptance Criteria
[x] No panic occurs when reading uninitialized contract state.

[x] A clear Error::NotInitialized (or equivalent) is returned.

[x] Test covers the uninitialized-state path.

Additional Notes
This change improves code quality and consistency across the contract.

Issue Reference
Closes #1944

- storage.rs: get_admin returns Result<Address, Error> using ok_or(Error::NotInitialized)
- lib.rs: get_admin signature updated to return Result<Address, Error>
- init.rs: upgrade_authorize handles Result from get_admin via match
- Fixed missing closing brace for mod layout_tests in storage.rs
- Removed decorative comment banners across src/ files

Closes EarnQuestOne#1944
@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Well done on the job done so far!
Kindly resolve conflict and ensure the workflow pass

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.

Replace .expect("Contract not initialized") panic with proper Error return

2 participants