Fix callback executing before output has been written

The same callback can now receive error, if any.