Unable to update hook

When updating a hook containing certain code using the deploy cli, the update fails.

Deploying this code with the CLI works fine. However, when running the same deploy again, it breaks. I am only deploying this and some Rules (importing from directories), and this is the part that does not work. From what I gather, deployment of hooks fails if some faulty code is already present within the hook. If you manually delete the hook, deployment works again. Allow delete is set to false.

A second run of the import command produces this:

Changing the code in the hook to the following fixed the issue:

I speculate that it has something to do with the callbacks, branching etc. But I could not figure out how to properly structure it so deployment worked. And even if my code was faulty, I’d expect it to either deploy anyway or fail on first deploy. And I would also expect a better error.

Deploy CLI version is 5.2.1

I have exactly the same problem. Anyone got a suggestion? This is quiet a common issue , please suggest me if you find any solution for it .

Checked with importing from yaml too, same problem.