When template generation fails, throw invalid_argument