Replace .expect panic with Error::NotInitialized return in get_admin#2071
Open
Meet-hybrid wants to merge 6 commits into
Open
Replace .expect panic with Error::NotInitialized return in get_admin#2071Meet-hybrid wants to merge 6 commits into
Meet-hybrid wants to merge 6 commits into
Conversation
- 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
Contributor
|
Well done on the job done so far! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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