Correct syntax and logic of execution

The patch fixes the problem which prevents to emit the "tenant migrated"
event in case of errors.