Skip to content

CLI crash when JSON objects cannot be decoded. #118

Description

@jathanism

Related to dropbox/nsot#219

Trying to create an object on a non-existent site is unhandled.

This should be caught and return a human-readable error, not a traceback:

$ nsot networks add -c 2001:db8::/64
Traceback (most recent call last):
  File "/Users/jathan/sandbox/virtualenvs/nsot/bin/nsot", line 9, in <module>
    load_entry_point('pynsot==1.0', 'console_scripts', 'nsot')()
  File "/Users/jathan/sandbox/virtualenvs/nsot/lib/python2.7/site-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/Users/jathan/sandbox/virtualenvs/nsot/lib/python2.7/site-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/Users/jathan/sandbox/virtualenvs/nsot/lib/python2.7/site-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/jathan/sandbox/virtualenvs/nsot/lib/python2.7/site-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/jathan/sandbox/virtualenvs/nsot/lib/python2.7/site-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/jathan/sandbox/virtualenvs/nsot/lib/python2.7/site-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/Users/jathan/sandbox/virtualenvs/nsot/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Users/jathan/sandbox/virtualenvs/nsot/lib/python2.7/site-packages/pynsot/commands/cmd_networks.py", line 116, in add
    ctx.obj.add(data)
  File "/Users/jathan/sandbox/virtualenvs/nsot/lib/python2.7/site-packages/pynsot/app.py", line 489, in add
    self.handle_error(action, data, err)
  File "/Users/jathan/sandbox/virtualenvs/nsot/lib/python2.7/site-packages/pynsot/app.py", line 222, in handle_error
    body = resp.json()
  File "/Users/jathan/sandbox/virtualenvs/nsot/lib/python2.7/site-packages/requests/models.py", line 808, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 382, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions