Error responses are double JSON encoded

Bug #1662228 reported by Sam Betts
14
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Ironic
Triaged
Medium
Unassigned

Bug Description

Error responses from the Ironic API return as a double JSON encoded error message. An example of this is: {"error_message": "{\"debuginfo\": null, \"faultcode\": \"Client\", \"faultstring\": \"The requested action \\\"provide\\\" can not be performed on node \\\"7c b3fb9f-780e-48ab-8e22-20dff73d4b1d\\\" while it is in state \\\"active\\\".\"}"}

The JSON dictionary inside of error_message does not need to be string encoded, this results in applications consuming the API to have to decode the outer body of the response and then (and only if the error_message exists) decode again the internal body of the message.

Even our own python-ironicclient falls victim to this: https://github.com/openstack/python-ironicclient/blob/master/ironicclient/common/http.py#L77

After some investigation it appears the response ends up encoded this way because of two separate places: https://github.com/openstack/wsme/blob/ecaf3aa40f0fc09a30bf2e47b42bf4c4314c1dc0/wsmeext/pecan.py#L109

and

https://github.com/openstack/ironic/blob/master/ironic/api/middleware/parsable_error.py#L35

The first place creates the

{\"debuginfo\": null, \"faultcode\": \"Client\", \"faultstring\": \"The requested action \\\"provide\\\" can not be performed on node \\\"7c b3fb9f-780e-48ab-8e22-20dff73d4b1d\\\" while it is in state \\\"active\\\".\"}

body, and then the middleware wraps it the second time.

Sam Betts (sambetts)
description: updated
Changed in ironic:
importance: Undecided → Medium
status: New → Triaged
Changed in ironic:
assignee: nobody → Ramamani Yeleswarapu (ramamani-yeleswarapu)
Changed in ironic:
assignee: Ramamani Yeleswarapu (ramamani-yeleswarapu) → nobody
Changed in ironic:
assignee: nobody → Abdallah Banishamsa (abdallahb)
Revision history for this message
Dmitry Tantsur (divius) wrote :

Hi! Unassigning this bug after nearly 2 months of inactivity.

Changed in ironic:
assignee: Abdallah Banishamsa (abdallahb) → nobody
Revision history for this message
Kaifeng Wang (kaifeng) wrote :

The solution is straightforward, but the change will break quite amount of unit tests, I wonder if it worth the efforts, or if there is any decent way to achieve it.

Revision history for this message
Rob Cresswell (robcresswell-deactivatedaccount) wrote :

I'd have thought the unit tests could be fixed by a single sed for the triple backslashes? This is a pain in the ass for any API consumers (clients, UIs) as you end up indefinitely carrying a hack on Ironics error messages.

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.