CLI crash when JSON objects cannot be decoded.
- Dominant language
- Python
- Stars
- 46
- Forks
- 22
- PR merge metrics
- No merged PRs in 30d
Description
Related to https://github.com/dropbox/nsot/issues/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:
``` bash
$ nsot networks add -c 2001:db8::/64
Traceback (most recent call last):
File "/Users/jathan/sandbox/virtualenvs/nsot/bin/nsot", line 9, in
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
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in pynsot/app.py at handle_error, called from the networks add path in pynsot/commands/cmd_networks.py. Reproduce the failure with `nsot networks add -c 2001:db8::/64` against a non-existent site and inspect how the response is decoded. Done means the CLI returns a human-readable error instead of a traceback when the response is not JSON.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100