Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update translate to use defensive! #2985

Merged
merged 15 commits into from
Jan 19, 2024
Merged
4 changes: 2 additions & 2 deletions substrate/frame/support/src/storage/generator/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ where
let value = match unhashed::get::<O>(&current_key) {
Some(value) => value,
None => {
log::error!("Invalid translate: fail to decode old value");
crate::defensive!("Invalid translation: failed to decode old value");
liamaharon marked this conversation as resolved.
Show resolved Hide resolved
return Some(current_key)
},
};
Expand All @@ -205,7 +205,7 @@ where
let key = match K::decode(&mut key_material) {
Ok(key) => key,
Err(_) => {
log::error!("Invalid translate: fail to decode key");
crate::defensive!("Invalid translation: failed to decode key");
liamaharon marked this conversation as resolved.
Show resolved Hide resolved
return Some(current_key)
},
};
Expand Down
3 changes: 2 additions & 1 deletion substrate/frame/support/src/storage/types/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,8 @@ where
///
/// By returning `None` from `f` for an element, you'll remove it from the map.
///
/// NOTE: If a value fail to decode because storage is corrupted then it is skipped.
/// NOTE: If a value fails to decode because storage is corrupted, then it will log an error and
/// be skipped in production, or panic in development.
pub fn translate<O: Decode, F: FnMut(Key, O) -> Option<Value>>(f: F) {
<Self as crate::storage::IterableStorageMap<Key, Value>>::translate(f)
}
Expand Down
Loading