invalid input cause 500 error

Bug #1428462 reported by ZhiQiang Fan
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Ceilometer
Invalid
Undecided
Unassigned
WSME
Fix Released
Undecided
Stéphane Bisinger

Bug Description

It may be actually wsme bug

find when test master branch, reproduce command:

# curl -g -i -X 'POST' 'http://127.0.0.1:8777/v2/meters/1' -H 'User-Agent: ceilometerclient.openstack.common.apiclient' -H 'Content-Type: application/json' -H "X-Auth-Token: $(keystone token-get | awk 'NR==5{print $4}')" -d '[{"counter_name": "1", "resource_id": "1", "counter_unit": "1", "counter_volume": "1", "project_id": "", "counter_type": "gauge", "source": "xyz"]'
HTTP/1.0 500 Internal Server Error
Content-Type: application/json
Content-Length: 140
x-openstack-request-id: req-127a66d2-84a2-4bc8-8798-d3df0658f861
Server: Werkzeug/0.9.6 Python/2.7.6
Date: Thu, 05 Mar 2015 04:07:21 GMT

{"error_message": {"debuginfo": null, "faultcode": "Server", "faultstring": "Expecting ',' delimiter or '}': line 1 column 146 (char 145)"}}

the request's body is not an valid json string, but cause 500 error, server side prints:

ERROR wsme.api [-] Server-side error: "Expecting ',' delimiter or '}': line 1 column 146 (char 145)". Detail:
Traceback (most recent call last):

  File "/usr/local/lib/python2.7/dist-packages/wsmeext/pecan.py", line 78, in callfunction
    pecan.request.body, pecan.request.content_type

  File "/usr/local/lib/python2.7/dist-packages/wsme/rest/args.py", line 292, in get_args
    from_body = args_from_body(funcdef, body, mimetype)

  File "/usr/local/lib/python2.7/dist-packages/wsme/rest/args.py", line 238, in args_from_body
    body, datatypes, bodyarg=funcdef.body_type is not None

  File "/usr/local/lib/python2.7/dist-packages/wsme/rest/json.py", line 219, in parse
    jdata = json.loads(s)

  File "/usr/local/lib/python2.7/dist-packages/simplejson/__init__.py", line 505, in loads
    return _default_decoder.decode(s)

  File "/usr/local/lib/python2.7/dist-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)

  File "/usr/local/lib/python2.7/dist-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())

JSONDecodeError: Expecting ',' delimiter or '}': line 1 column 146 (char 145)

Revision history for this message
Srinivas Sakhamuri (srinivas-sakhamuri) wrote :

I think so I raised one sometime back on WSME: https://bugs.launchpad.net/wsme/+bug/1392409

Changed in wsme:
assignee: nobody → Stéphane Bisinger (kjir)
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to wsme (master)

Fix proposed to branch: master
Review: https://review.openstack.org/176804

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to wsme (master)

Reviewed: https://review.openstack.org/176804
Committed: https://git.openstack.org/cgit/stackforge/wsme/commit/?id=8d9f82d7fefd357b22c5d51754069ac05fd17159
Submitter: Jenkins
Branch: master

commit 8d9f82d7fefd357b22c5d51754069ac05fd17159
Author: Stéphane Bisinger <email address hidden>
Date: Thu Apr 23 16:37:14 2015 +0200

    Return a 400 status code on invalid JSON input

    Instead of returning a 500 HTTP status code, return a 400 status code when the
    received input is invalid JSON.
    Also add a unit test for this case.

    Closes-Bug: #1428462
    Change-Id: Id02de0a7b8fcbcb07f7ac534519dcdc1cbb04839

Changed in wsme:
status: In Progress → Fix Committed
gordon chung (chungg)
Changed in ceilometer:
status: New → Won't Fix
status: Won't Fix → Invalid
Changed in wsme:
milestone: none → 0.8.0
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.