rescrv/libmacaroons

python bindings: produce better error when format not recognized

Opened this issue · 1 comments

When we pass an unknown format to macaroon.serialize, it produces this error:

>>> m.serialize(format='json1')
Exception KeyError: ('json1',) in 'macaroons.Macaroon.version' ignored
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "bindings/python/macaroons.pyx", line 179, in macaroons.Macaroon.serialize (bindings/python/macaroons.c:2215)
    if self.is_json(format):
  File "bindings/python/macaroons.pyx", line 289, in macaroons.Macaroon.is_json (bindings/python/macaroons.c:3914)
    '1': False}[v]
KeyError: 'json1'

It would be nice if it made it clearer what the error signifies (for example by raising an exception which mentions that it's an unknown format, possibly stating the possible format values, as there is no documentation for that, AFAICS)

This would be great to have. I didn't document the format well because I'd like to move to the v2 binary format (which is much more compact) and the well-specified JSON equivalent. Unfortunately, I never had time to investigate UTF-8 issues to support JSON correctly, and I didn't want to support it incorrectly.

I've just moved to a new job and don't know if I have the cycles to make this fix, but wanted to give you a signal that this would be a beneficial change.