Closed alexwlchan closed 4 years ago
JSON
>>> import json
>>> print(json.loads(""))
Traceback (most recent call last):
...
"/usr/local/Cellar/python/3.6.4_4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
YAML
>>> import yaml
>>> print(yaml.safe_load(""))
None
An Exception, or None
seems to be most appropriate. Definitely not {}
though (in my opinion).
The empty string isn’t a valid JSON object, but I think it might be valid HCL.
If I create an empty main.tf
file in a directory and run terraform plan
(which is how I usually interact with HCL), it runs fine. That’s how I uncovered this – one of my Terraform modules has an empty file which Terraform is happy to work with, but pyhcl didn't like.
Fixed in PR #68
If you try to parse an empty string (or in my case, an empty file), you get an error. Here’s a minimal example:
This is the error it throws:
I think this could be returned as
{}
and not throw an exception. I haven’t checked what the Golang parser does here.Package versions: