From 91b09eb848a33e6c7187d6add40df6e787fc564e Mon Sep 17 00:00:00 2001 From: Mahmoud Zalt Date: Fri, 6 Oct 2017 07:25:01 +0300 Subject: [PATCH] Add a message informing users about parsing errors I couldn't tell why I got this error `.env: line 129: syntax error near unexpected token `('` after adding a bunch of plugins. I didn't knew what most of the plugins do, nor what the `dotenv` plugin is doing behind the scene! After figuring out the problem, I though it would be much better displaying an error message only in case there are some parsing errors. Now I would get this: ``` Found some errors while parsing your .env file: .env: line 129: syntax error near unexpected token `(' ``` --- plugins/dotenv/dotenv.plugin.zsh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/dotenv/dotenv.plugin.zsh b/plugins/dotenv/dotenv.plugin.zsh index 9dd784229..efef38e2e 100644 --- a/plugins/dotenv/dotenv.plugin.zsh +++ b/plugins/dotenv/dotenv.plugin.zsh @@ -2,7 +2,11 @@ source_env() { if [[ -f .env ]]; then - source .env + if errs=$(bash -n .env 2>&1); + then source .env; + else + printf '%s\n' "Found some errors while parsing your .env file: " "$errs"; + fi fi }