Improve error handling in domgen