Skip to content

Return TokenizationError instead of panicking on invalid content metadata length - #500

Merged
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
RUKAYAT-CODER:fix/485-mint-content-token-panic
Aug 10, 2026
Merged

Return TokenizationError instead of panicking on invalid content metadata length#500
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
RUKAYAT-CODER:fix/485-mint-content-token-panic

Conversation

@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Summary

ContentTokenization::mint (contracts/teachlink/src/tokenization.rs) used .unwrap() on BytesValidator::validate_length() for title, description, and content_hash. An out-of-range value — most notably a content_hash that isn't exactly 32 bytes — panicked the entire contract invocation (HostError: Error(WasmVm, InvalidAction)) instead of returning a recoverable Result::Err.

Fix

Replaced the three .unwrap() calls with .map_err(|_| TokenizationError::InvalidMetadata)?, so callers now get a normal contract error instead of the invocation panicking. mint's enclosing closure already returns TokenizationResult<u64>, so this propagates cleanly through the existing reentrancy::with_guard wrapper.

Closes #485

…data length

mint() used .unwrap() on BytesValidator::validate_length() for title,
description, and content_hash, so an out-of-range value (e.g. a
content_hash that isn't exactly 32 bytes) panicked the whole invocation
instead of returning a recoverable contract error. Propagate
TokenizationError::InvalidMetadata via ? instead.

Closes rinafcode#485
@RUKAYAT-CODER
RUKAYAT-CODER merged commit 7bab9f4 into rinafcode:main Aug 10, 2026
4 checks passed
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.

mint_content_token panics instead of returning an error for invalid content_hash length

2 participants