awslabs/aws-cfn-template-flip

Incorrect error returned on YAML parsing error: json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

rychoo2 opened this issue · 2 comments

When parsing an incorrect yaml, the actual parsing error is not raised, only the previous misleading JSON error is returned instead:

Error Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/cfn_flip/__init__.py", line 27, in load data = load_json(template) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/cfn_tools/__init__.py", line 20, in load_json return json.loads(source, object_pairs_hook=ODict) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/__init__.py", line 370, in loads return cls(**kw).decode(s) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

See:

except ValueError as e:
try:
data = load_yaml(template)
return data, "yaml"
except Exception:
raise e

I would expect to see the YAML parsing error.

Can you share the invalid Yaml document to add to the tests?

Closed due to inactivity.