added template support for errors