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

Missing intervention definitions do not result in a 500 error #18

Closed
rob-smallshire opened this issue Nov 2, 2015 · 2 comments
Closed

Comments

@rob-smallshire
Copy link
Contributor

If an intervention definition is not found – for example because the interventions have not been installed – any attempt to run the simulator results in an error server side, but no error is apparently reported back to the client. I'd expect a 500 error of some sort.

$ pserve development.ini 
Starting server in PID 84091.
serving on http://0.0.0.0:6543
2015-11-02 21:20:07,060 ERROR [pyramid_debugtoolbar][waitress] Exception at http://0.0.0.0:6543/simulate
traceback url: http://0.0.0.0:6543/_debug_toolbar/exception?token=62275c7866355c783032795c7865325f4e2e5c786566325c78666127&tb=4428651208
multiprocessing.pool.RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/Users/rjs/dev/bark-spider/bark_spider/intervention.py", line 40, in _parse_intervention
    cls = _interventions()[command]
KeyError: 'add'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/multiprocessing/pool.py", line 119, in worker
    result = (True, func(*args, **kwds))
  File "/Users/rjs/dev/bark-spider/bark_spider/simulation/simulation.py", line 27, in run_simulation
    schedule = make_schedule(**params)
  File "/Users/rjs/dev/bark-spider/bark_spider/simulation/schedule.py", line 74, in make_schedule
    parse_interventions(StringIO(interventions)))
  File "/Users/rjs/dev/bark-spider/bark_spider/simulation/schedule.py", line 14, in __init__
    self._interventions = sorted(interventions, key=lambda i: i.time)
  File "/Users/rjs/dev/bark-spider/bark_spider/intervention.py", line 45, in _parse_intervention
    command, line))
ValueError: Unknown command "add" while parsing interventions. (full command=add 100 10)
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/rjs/dev/virtualenvs/bark-spider/lib/python3.4/site-packages/pyramid_debugtoolbar/toolbar.py", line 192, in toolbar_tween
    response = _handler(request)
  File "/Users/rjs/dev/virtualenvs/bark-spider/lib/python3.4/site-packages/pyramid_debugtoolbar/panels/performance.py", line 57, in resource_timer_handler
    result = handler(request)
  File "/Users/rjs/dev/virtualenvs/bark-spider/lib/python3.4/site-packages/pyramid/tweens.py", line 21, in excview_tween
    response = handler(request)
  File "/Users/rjs/dev/virtualenvs/bark-spider/lib/python3.4/site-packages/pyramid/router.py", line 163, in handle_request
    response = view_callable(context, request)
  File "/Users/rjs/dev/virtualenvs/bark-spider/lib/python3.4/site-packages/pyramid/config/views.py", line 329, in attr_view
    return view(context, request)
  File "/Users/rjs/dev/virtualenvs/bark-spider/lib/python3.4/site-packages/pyramid/config/views.py", line 305, in predicate_wrapper
    return view(context, request)
  File "/Users/rjs/dev/virtualenvs/bark-spider/lib/python3.4/site-packages/pyramid/config/views.py", line 355, in rendered_view
    result = view(context, request)
  File "/Users/rjs/dev/virtualenvs/bark-spider/lib/python3.4/site-packages/pyramid/config/views.py", line 501, in _requestonly_view
    response = view(request)
  File "/Users/rjs/dev/bark-spider/bark_spider/views.py", line 42, in simulate_route
    lambda: _async_simulation(sim_params))
  File "/Users/rjs/dev/bark-spider/bark_spider/simulation_db.py", line 15, in add_results
    results = gen()
  File "/Users/rjs/dev/bark-spider/bark_spider/views.py", line 42, in <lambda>
    lambda: _async_simulation(sim_params))
  File "/Users/rjs/dev/bark-spider/bark_spider/views.py", line 24, in _async_simulation
    return result.get(timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/multiprocessing/pool.py", line 599, in get
    raise self._value
ValueError: Unknown command "add" while parsing interventions. (full command=add 100 10)
@abingham
Copy link
Collaborator

The parsing-errors branch addresses this issue. I've decided to return HTTP/400 when there is a problem parsing interventions. Since I don't think we can distinguish between a mistyped intervention and one which is not installed, there's no condition under which I felt a 500 was correct.

Give it a try and let me know what you think.

@abingham
Copy link
Collaborator

Fixed at 5812938

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants