Better template error handling