Hello everybody,
I have the following code which works but my tests are failing. The reason for this seems to be, that the compiler optimizes away the unwrap_or_else
call (At least this is what my debugger told me).
<pallet_vesting::Module<T>>::vested_transfer(
T::Origin::from(RawOrigin::Signed(from.clone())),
to,
schedule
).map_err(|err| {
T::Currency::transfer(&who, &from, direct_reward, AllowDeath)
.err()
.unwrap_or_else(|| err)
})?;
Details
In both the following cases, the vested_transfer
fails. But in one of the cases the returned value from the map_err
is gibberish.
Case 1 - transfer
fails
The call of transfer fails and an error is returned. The code then correctly returns an Err(ERROR_TYPE)
value.
Case 2 - transfer
does NOT fail
The call of transfer succeeds and I want to return the previous error value via the unwrap_or_else
call. The returned value is an byte-array:
Questions
- Is this expected behavior?
- How to correctly return the error upon the success of the
transfer
call?