Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI crash when JSON objects cannot be decoded. #118

Open
jathanism opened this issue Sep 29, 2016 · 1 comment
Open

CLI crash when JSON objects cannot be decoded. #118

jathanism opened this issue Sep 29, 2016 · 1 comment

Comments

@jathanism
Copy link
Contributor

jathanism commented Sep 29, 2016

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
@jathanism
Copy link
Contributor Author

This in fact happens any time a JSON payload is expected to come back and one doesn't. This should be fixed across the board.

Here's another example w/ a basic typo in the cidr:

$ nsot networks list -c 10.254.33.0/24closest_parent
^[[ATraceback (most recent call last):
  File "/srv/dbops/tools/nsot", line 11, in <module>
    sys.exit(app())
  File "/srv/pynsot/envs/pynsot/lib/python2.7/site-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/srv/pynsot/envs/pynsot/lib/python2.7/site-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/srv/pynsot/envs/pynsot/lib/python2.7/site-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/srv/pynsot/envs/pynsot/lib/python2.7/site-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/srv/pynsot/envs/pynsot/lib/python2.7/site-packages/click/core.py", line 1037, in invoke
    return Command.invoke(self, ctx)
  File "/srv/pynsot/envs/pynsot/lib/python2.7/site-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/srv/pynsot/envs/pynsot/lib/python2.7/site-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/srv/pynsot/envs/pynsot/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/srv/pynsot/envs/pynsot/lib/python2.7/site-packages/pynsot/commands/cmd_networks.py", line 272, in list
    ctx.obj.list(data, display_fields=DISPLAY_FIELDS)
  File "/srv/pynsot/envs/pynsot/lib/python2.7/site-packages/pynsot/app.py", line 635, in list
    self.handle_error(action, data, err)
  File "/srv/pynsot/envs/pynsot/lib/python2.7/site-packages/pynsot/app.py", line 222, in handle_error
    body = resp.json()
  File "/srv/pynsot/envs/pynsot/lib/python2.7/site-packages/requests/models.py", line 808, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/local/python/python-2.7.7/lib/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/usr/local/python/python-2.7.7/lib/python2.7/json/decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/python/python-2.7.7/lib/python2.7/json/decoder.py", line 384, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

In both cases the call do body.json() should be wrapped and/or the response code should be evaluated. This might need to be coupled w/ a server-side fix.

@jathanism jathanism changed the title Trying to create an object on a non-existent site is unhandled CLI crash when JSON objects cannot be decoded. Nov 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant