Fix compiling invalid file

* Improve hooks error handling