CouchDB
  1. CouchDB
  2. COUCHDB-1332

Invalid JSON shows debug level info in response

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.1.1
    • Fix Version/s: 1.2, 1.3
    • Component/s: HTTP Interface
    • Labels:
    • Environment:

      OS X 10.7.1 Macbook Pro

    • Skill Level:
      New Contributors Level (Easy)

      Description

      When sending invalid JSON in an HTTP request, the response contains the string "invalid UTF-8 JSON: " followed by an erlang tuple and the escaped internal form of the string. I noticed that this error tuple is only logged when the [log] level is debug. I would propose that the error tuple only be show in the client response when debug is on as well.

      1. COUCHDB-1332.patch
        1 kB
        Christopher Bonhage

        Activity

        Hide
        Robert Newson added a comment -

        Removing 1.0.4/1.1.2.

        Show
        Robert Newson added a comment - Removing 1.0.4/1.1.2.
        Hide
        Christopher Bonhage added a comment -

        Resolved by COUCHDB-1406

        Show
        Christopher Bonhage added a comment - Resolved by COUCHDB-1406
        Hide
        Christopher Bonhage added a comment -

        The "reason" key cannot be easily matched against, and my users are incredibly fearful of "teh codes" (erlang tuples, binaries, and cryptically useful feedback) in the error string.
        This patch makes non-debug-level JSON errors more aesthetically pleasing. Ideally, the details of the parse error could be included in separate keys on the error object instead of being stringified into the reason key, but that's "nice to have", since the debug message is eminently readable to anyone who understands what escaping means. Unfortunately, they don't seem to appreciate my suggestion of simply sending valid JSON.

        Example errors:

        {"error":"bad_request","reason":"invalid UTF-8 JSON: error,{9,\"lexical error: invalid char in json text.\\n\",\n <<\"

        {\\\"note\\\":asd\\\"dfsdfsdfsdfsdf\\\"}

        \">>}"}

        {"error":"bad_request","reason":"invalid UTF-8 JSON: error,{2,\n \"parse error: invalid object key (must be a string)\\n\",\n <<\"{{\\\"note\\\":\\\"dsdfsdfsdfsdf\\\"}\">>}"}

        Show
        Christopher Bonhage added a comment - The "reason" key cannot be easily matched against, and my users are incredibly fearful of "teh codes" (erlang tuples, binaries, and cryptically useful feedback) in the error string. This patch makes non-debug-level JSON errors more aesthetically pleasing. Ideally, the details of the parse error could be included in separate keys on the error object instead of being stringified into the reason key, but that's "nice to have", since the debug message is eminently readable to anyone who understands what escaping means. Unfortunately, they don't seem to appreciate my suggestion of simply sending valid JSON. Example errors: {"error":"bad_request","reason":"invalid UTF-8 JSON: error,{9,\"lexical error: invalid char in json text.\\n\" ,\n <<\" {\\\"note\\\":asd\\\"dfsdfsdfsdfsdf\\\"} \">>}"} {"error":"bad_request","reason":"invalid UTF-8 JSON: error,{2,\n \"parse error: invalid object key (must be a string)\\n\" ,\n <<\"{{\\\"note\\\":\\\"dsdfsdfsdfsdf\\\"}\">>}"}
        Hide
        Robert Newson added a comment -

        Why?

        Show
        Robert Newson added a comment - Why?
        Hide
        Christopher Bonhage added a comment -

        this patch checks to see if couch_log:debug_on and shows a simplified error message ("invalid UTF-8 JSON") if debug is off.

        Show
        Christopher Bonhage added a comment - this patch checks to see if couch_log:debug_on and shows a simplified error message ("invalid UTF-8 JSON") if debug is off.

          People

          • Assignee:
            Unassigned
            Reporter:
            Christopher Bonhage
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development