cmmorrow / build-magic

A general purpose build/install/deploy tool.
MIT License
9 stars 2 forks source link

Providing an improperly formatted dotenv file silently passes #94

Open cmmorrow opened 2 years ago

cmmorrow commented 2 years ago

Describe the bug If using the --dotenv option from the command-line or dotenv: in a Config File and providing a file that is not a dotenv file doesn't cause an error. It would be better to let the user know that they provided an improperly formatted instead of continuing with executing commands and potentially failing later.

To Reproduce Steps to reproduce the behavior:

  1. Run build-magic --dotenv [some file] echo hello where [some file] is any file that isn't a dotenv file.

Expected behavior An improperly formatted dotenv file should raise an error and communicate the impropriety to the user.

Additional context The dotenv file is read and parsed in cli/parse_dotenv_file() and the logic simply continues to the next line if it doesn't contain an "=":

envs = {}
    for line in dotenv.readlines():
        if line.startswith('#'):
            continue
        if '=' not in line:
            continue
        env, val = line.split('=', maxsplit=1)
        envs.update({env.strip(): val.strip()})

The checks inside this loop should be replaced with a single step that validates the dotenv file.

Nightfurex commented 2 years ago

Can i try these.

cmmorrow commented 2 years ago

Feel free to submit a pull request. I've assigned the issue to you and sent you an invitation to the project.

Nightfurex commented 2 years ago

Feel free to submit a pull request. I've assigned the issue to you and sent you an invitation to the proS So by "improperly formatted dotenv file" you are talking about the contents of the .env file right?

cmmorrow commented 2 years ago

Correct, the content of the dotenv file does not contain equal sign separated key value pairs on each line. You can test against a plane text file or binary file like a jpg.