binbashar / leverage

Binbash Leverage CLI intended to orchestrate Leverage Reference Architecture for AWS (www.binbash.co/leverage)
https://pypi.org/project/leverage/
Apache License 2.0
17 stars 2 forks source link

Bug | error not handled when short name is wrong #145

Closed juanmatias closed 1 year ago

juanmatias commented 2 years ago

What?

If mistakenly the short project name is set with spaces (e.g. you missed the short and long names places), CLI fails not catching the error:

╰─ leverage project create
[13:10:23.203] INFO     Creating project directory structure.                                                                                                 
[13:10:23.284] INFO     Finished creating directory structure.                                                                                                
[13:10:23.285] INFO     Setting up common base files.                                                                                                         
[13:10:23.294] INFO     Account: Setting up management.                                                                                                       
[13:10:23.295] INFO             Layer: Setting up config.                                                                                                     
[13:10:23.298] INFO             Layer: Setting up base-identities.                                                                                            
[13:10:23.315] INFO             Layer: Setting up organizations.                                                                                              
[13:10:23.320] INFO             Layer: Setting up base-tf-backend.                                                                                            
[13:10:23.321] INFO             Layer: Setting up security-base.                                                                                              
[13:10:23.322] INFO     Account: Setting up security.                                                                                                         
[13:10:23.323] INFO             Layer: Setting up config.                                                                                                     
[13:10:23.326] INFO             Layer: Setting up base-identities.                                                                                            
[13:10:23.333] INFO             Layer: Setting up base-tf-backend.                                                                                            
[13:10:23.334] INFO             Layer: Setting up security-base.                                                                                              
[13:10:23.335] INFO     Account: Setting up shared.                                                                                                           
[13:10:23.336] INFO             Layer: Setting up config.                                                                                                     
[13:10:23.339] INFO             Layer: Setting up base-identities.                                                                                            
[13:10:23.340] INFO             Layer: Setting up base-network.                                                                                               
[13:10:23.346] INFO             Layer: Setting up base-tf-backend.                                                                                            
               INFO             Layer: Setting up security-base.                                                                                              
[13:10:23.347] INFO     Project configuration finished.                                                                                                       
[13:10:23.348] INFO     Reformatting terraform configuration to the standard style.                                                                           
Traceback (most recent call last):
  File "/home/jdelacamara/.local/share/virtualenvs/leverage-2riWuZj5/bin/leverage", line 8, in <module>
    sys.exit(leverage())
  File "/home/jdelacamara/.local/share/virtualenvs/leverage-2riWuZj5/lib/python3.10/site-packages/click/core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "/home/jdelacamara/.local/share/virtualenvs/leverage-2riWuZj5/lib/python3.10/site-packages/click/core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "/home/jdelacamara/.local/share/virtualenvs/leverage-2riWuZj5/lib/python3.10/site-packages/click/core.py", line 1668, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/jdelacamara/.local/share/virtualenvs/leverage-2riWuZj5/lib/python3.10/site-packages/click/core.py", line 1668, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/jdelacamara/.local/share/virtualenvs/leverage-2riWuZj5/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/jdelacamara/.local/share/virtualenvs/leverage-2riWuZj5/lib/python3.10/site-packages/click/core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "/home/jdelacamara/.local/share/virtualenvs/leverage-2riWuZj5/lib/python3.10/site-packages/leverage/modules/project.py", line 311, in create
    terraform = TerraformContainer(get_docker_client())
  File "/home/jdelacamara/.local/share/virtualenvs/leverage-2riWuZj5/lib/python3.10/site-packages/leverage/container.py", line 376, in __init__
    super().__init__(client)
  File "/home/jdelacamara/.local/share/virtualenvs/leverage-2riWuZj5/lib/python3.10/site-packages/leverage/container.py", line 81, in __init__
    self.env_conf = load_env()
  File "/home/jdelacamara/.local/share/virtualenvs/leverage-2riWuZj5/lib/python3.10/site-packages/leverage/conf.py", line 57, in load
    for key, val in config_file:
  File "/home/jdelacamara/.local/share/virtualenvs/leverage-2riWuZj5/lib/python3.10/site-packages/yaenv/core.py", line 261, in __iter__
    yield from self.vars.items()
  File "/usr/lib/python3.10/functools.py", line 981, in __get__
    val = self.func(instance)
  File "/home/jdelacamara/.local/share/virtualenvs/leverage-2riWuZj5/lib/python3.10/site-packages/yaenv/core.py", line 332, in vars
    envvars = list(filter(None.__ne__, map(EnvVar, f.readlines())))
  File "/home/jdelacamara/.local/share/virtualenvs/leverage-2riWuZj5/lib/python3.10/site-packages/yaenv/core.py", line 85, in __new__
    raise EnvError(f'Surplus token in line: {line}')
yaenv.core.EnvError: Surplus token in line: PROJECT=Lula Dream

This error should be handled by CLI and a nicer message should be shown.

exequielrafaela commented 1 year ago

We'll follow-up this issue here https://github.com/binbashar/leverage/issues/212