question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

In debug mode, comments and empty lines almost appear as invalid syntax

See original GitHub issue

I use Vue CLI service to run my project, which uses dotenv. While trying to debug something with Express that’s running in Vue’s (really Webpack’s) dev server, I set an environment variable DEBUG=express:router.

I appreciate that none of this has anything to do with dotenv, but because I’m using a certain toolchain, and the minor issue I see is IMHO a dotenv issue, I hope you don’t mind that I am reporting the following issue here.

Because the DEBUG variable is set (to anything, I guess), dotenv becomes verbose. I can live with that, it’s only at startup, and not a very big deal. So by extension, this issue is not a big one or fatal one.

As dotenv starts parsing my files, it prints this for every line that is either a comment or an empty line:

[dotenv][DEBUG] did not match key and value when parsing line 2: # this is a comment

While not technically incorrect, it comes across as if my file has a syntax error in it, even though the documentation states that comments like this are allowed, and I assume empty lines are too.

My suggestion to improve this would be that the parser not just detect key/value pairs, but also comments and empty lines, and only prints a debug message for lines that follow no known syntax.

Thank you.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
motdotlacommented, Jan 17, 2022

My suggestion to improve this would be that the parser not just detect key/value pairs, but also comments and empty lines, and only prints a debug message for lines that follow no known syntax.

We agree with you. Use v13.0.1. It has fixed this up. It now ignores comments and empty lines in the debug output.

https://github.com/motdotla/dotenv/blob/v13.0.1/CHANGELOG.md#1301-2022-01-16

1reaction
motdotlacommented, Jan 11, 2022

Thank you for raising this @ronkorving. It’s a scenario we did not anticipate. We are going to overhaul the debug mode soon - and we will fix this then.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invalid Syntax in Python: Common Reasons for SyntaxError
The solution to this is to make all lines in the same Python code file use either tabs or spaces, but not both....
Read more >
Invalid Syntax error when running python from inside Visual ...
When you use "run selection/line in python terminal" command, VS Code starts python interpreter and doesn`t quit it after completion.
Read more >
SyntaxError: invalid syntax - Python Morsels
Python's "invalid syntax" error message comes up often, especially when you're first learning Python. What usually causes this error and how can you...
Read more >
Errors and exceptions — Object-Oriented Programming in ...
If a program is syntactically correct – that is, free of syntax errors – it will be run by the Python interpreter. However,...
Read more >
How to Think Like a Computer Scientist: Learning with Python ...
If you are not sure, try putting an obvious and deliberate syntax error at the beginning of the program. Now run (or import)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found