Skip to content

Commit

Permalink
Added exception handling for j2 templates
Browse files Browse the repository at this point in the history
Signed-off-by: Vadym Hlushko <vadymh@nvidia.com>
  • Loading branch information
vadymhlushko-mlnx committed Nov 16, 2021
1 parent 6a7d7fa commit afc4afb
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions sonic_cli_gen/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ def generate_cli_plugin(

loader = jinja2.FileSystemLoader(templates_path)
j2_env = jinja2.Environment(loader=loader)
template = j2_env.get_template(cli_group + '.py.j2')
try:
template = j2_env.get_template(cli_group + '.py.j2')
except jinja2.exceptions.TemplateNotFound:
self.logger.error(' Templates for auto-generation does NOT exist in folder {}'.format(templates_path))

plugin_path = get_cli_plugin_path(cli_group, plugin_name + '_yang.py')

Expand All @@ -67,7 +70,7 @@ def remove_cli_plugin(self, cli_group, plugin_name):
os.remove(plugin_path)
self.logger.info(' {} was removed.'.format(plugin_path))
else:
self.logger.info(' Path {} doest NOT exist!'.format(plugin_path))
self.logger.warning(' Path {} doest NOT exist!'.format(plugin_path))


def get_cli_plugin_path(command, plugin_name):
Expand Down

0 comments on commit afc4afb

Please sign in to comment.