fix error handling when rendering template