swaroopch / edn_format

EDN reader and writer implementation in Python, using PLY (lex, yacc)
https://swaroopch.com/2012/12/24/edn-format-python/
Other
131 stars 31 forks source link

Raise custom exceptions on syntax errors #46

Closed bfontaine closed 6 years ago

bfontaine commented 6 years ago

The current code raises SyntaxError on syntax errors. The problem with that is it’s impossible to catch EDN syntax errors and not other syntax errors. Also, SyntaxError is raised by the Python parser on bad code.

This PR adds a new exceptions namespace with a single class, EDNDecodeError, that inherits from ValueError. This mimicks Python’s json.decoder.JSONDecodeError.

Note that this is a breaking change, since code that catches SyntaxErrors to catch EDN issues won’t work anymore if it’s not changed to catch EDNDecodeErrors instead.