vapor-ware / synse-emulator-plugin

Emulator plugin for Synse
GNU General Public License v3.0
3 stars 3 forks source link

Return 500 code instead of internal server error html #6

Closed hoanhan101 closed 6 years ago

hoanhan101 commented 6 years ago

In the same context as #2, still playing around with write.

With an invalid argument like this

{
    "1": 1
}

it returns 500, which is what we expect:

{
    "http_code": 500,
    "error_id": 3001,
    "description": "invalid arguments",
    "timestamp": "2018-02-02 19:29:26.006628",
    "context": "Invalid data POSTed for write. Must contain \"action\" and/or \"raw\"."
}

However, in the situation where key is valid, value is an integer like this

{
    "raw": 1
}

or this

{
    "action": 1
}

it returns this html instead of 500:

<h1>Internal Server Error</h1>
<p>
        The server encountered an internal error and cannot complete
        your request.
    </p>

Here are the server's logs:

[2018-02-02 19:31:55 +0000] - (synse)[DEBUG] core:92: WRITE -> json: {'raw': 1}
[2018-02-02 19:31:55 +0000] - (synse)[DEBUG] cache:153: Creating meta cache
[2018-02-02 19:31:55 +0000] - (synse)[DEBUG] cache:166: plugins to scan: {'emulator': <synse.plugin.Plugin object at 0x7fdf8ed3b4e0>}
[2018-02-02 19:31:55 +0000] - (synse)[DEBUG] cache:172: emulator -- <Plugin (unix): emulator /tmp/synse/procs/emulator.sock>
[2018-02-02 19:31:55 +0000] - (root)[ERROR] handlers:105: Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/sanic/app.py", line 556, in handle_request
    response = await response
  File "/synse/synse/routes/core.py", line 99, in write_route
    response = await commands.write(rack, board, device, data)
  File "/synse/synse/commands/write.py", line 42, in write
    raw = [str.encode(raw)]
TypeError: descriptor 'encode' requires a 'str' object but received a 'int'

[2018-02-02 19:31:55 +0000] - (sanic.access)[INFO] server:325: "POST http://localhost:5000/synse/2.0/write/rack-1/vec/f52d29fecf05a195af13f14c7306cfed  500 144"
[2018-02-02 19:32:00 +0000] - (root)[INFO] server:193: KeepAlive Timeout. Closing connection.
hoanhan101 commented 6 years ago

More observations: If the key is invalid, it always return 500 as expected. If the key is valid, then:

edaniszewski commented 6 years ago

this is actually in issue in synse-server. will close here and open a corresponding issue in synse-server.