Closed wharter closed 2 years ago
Question about coding philosophy: to what extent do we want scripts like these to handle errors vs. raise them? For instance:
$ python rebuild_all_projects.py -t not-a-workspace
workspace_id: not-a-workspace
test: True
Traceback (most recent call last):
File "/home/lnathan/code/venvs/se-code/lib/python3.6/site-packages/luminoso_api/v5_client.py", line 235, in _request
result.raise_for_status()
File "/home/lnathan/code/venvs/se-code/lib/python3.6/site-packages/requests/models.py", line 953, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: FORBIDDEN for url: https://daylight.luminoso.com/api/v5/workspaces/not-a-workspace/
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "rebuild_all_projects.py", line 87, in <module>
main()
File "rebuild_all_projects.py", line 49, in main
projects = client.get("/workspaces/"+workspace_id)['projects']
File "/home/lnathan/code/venvs/se-code/lib/python3.6/site-packages/luminoso_api/v5_client.py", line 282, in get
return self._json_request('get', url, params=params)
File "/home/lnathan/code/venvs/se-code/lib/python3.6/site-packages/luminoso_api/v5_client.py", line 260, in _json_request
response = self._request(req_type, url, **kwargs)
File "/home/lnathan/code/venvs/se-code/lib/python3.6/site-packages/luminoso_api/v5_client.py", line 250, in _request
raise error_class(error)
luminoso_api.errors.LuminosoAuthError: {'workspace_id': 'not-a-workspace', 'permission': 'read', 'error': 'INADEQUATE_PERMISSION', 'message': 'The requested workspace does not exist or you do not have the required permission on it.'}
We could say that we want to catch that kind of error and summarize it; or we could say that letting the error filter out to the user is a sufficient way of informing them of what went wrong.
Thoughts?
I expect users that are running these scripts to have some python skills and an exception like that is straight forward.
It says: "The requested workspace does not exist or you do not have the required permission on it.'"
In reality we only ever advertise these scripts a "examples" they can use to develop their own scripts. We can fix all those kinds of places, but I don't think it's worth out time.
An on site user had a lot of projects fail their sentiment build. It would have been too much work to rebuild them all with the UI so we wrote this quick script for them to kick off the builds using the API.