2

A similar question exists here : Emit Events from hooks like on_initialize()

If we are performing fallible operations on pallet hooks like on_initialize and let's say we want to notify the frontend (e.g. polkadot-js), is there a way to emit errors in the same fashion as Self::deposit_event?

2 Answers 2

1

on_initialize must be infallible by definition.
Yes you can use Events to emit progress of failure from inside there. I don't think its hacky; the Scheduler does this when its unable to find a preimage. The MessageQueue pallet also does this while processing messages.
There is no other way to emit information here though.

1

I believe that is not the correct approach to design. Consider whether it's really necessary to include it in the on_initialize function.

However, you are able to deposit an event called XXXError(error_info) in the on_initialize function.

2
  • Can you elaborate on why it might be incorrect?
    – b0zero
    Sep 6, 2023 at 11:08
  • Due to some "lacking" of the existing Error system, there is a need to utilize the Event system as a replacement. However, this approach may seem counterintuitive for developers and users. Sep 6, 2023 at 11:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.