give better error in cases of invalid (or empty) templates
give better error in cases of invalid (or empty) templates

partly fixes #1535

Blaisorblade/stack,harendra-kumar/stack,martin-kolinek/stack,mrkkrp/stack,sjakobi/stack,luigy/stack,anton-dessiatov/stack,phadej/stack,AndrewRademacher/stack,phadej/stack,deech/stack,martin-kolinek/stack,achernyak/stack,MichielDerhaeg/stack,Fuuzetsu/stack,Blaisorblade/stack,harendra-kumar/stack,narrative/stack,deech/stack,juhp/stack,mrkkrp/stack,AndrewRademacher/stack,Heather/stack,achernyak/stack,Heather/stack,AndreasPK/stack,Fuuzetsu/stack,luigy/stack,anton-dessiatov/stack,MichielDerhaeg/stack,juhp/stack,AndreasPK/stack,sjakobi/stack,narrative/stack