I didn’t understand the first one.
What’s the different between the code you wrote and mine?
And is, it in in function.php
The PHP error should cause it to fail but in my case it doesn’t fail, it saves the post successfully even thought I want to return some message.