Websocket extension documentation/field wrong (SOLVED)

Describe the bug
On error the data.error key doesn’t exist, but is given as an example in the documentation. The error message can be found in data.message.

To Reproduce
Use the websocket callback from the documentation (slightly modified to run without a logger):

local function websocket_callback(self, conn, data)
	if data.event == websocket.EVENT_DISCONNECTED then
		print("Disconnected: " .. tostring(conn))
		self.connection = nil
	elseif data.event == websocket.EVENT_CONNECTED then
		self.connection = conn
		print("Connected: " .. tostring(conn))
	elseif data.event == websocket.EVENT_ERROR then
		print("Error: '" .. data.error .. "'")
	elseif data.event == websocket.EVENT_MESSAGE then
		print("Receiving: '" .. tostring(data.message) .. "'")
	end
end

and call a non-existing WS url so an error is generated.

Expected behaviour
Either the documentation adjusted or correct keys populated.

Defold version (REQUIRED):

  • Defold version: 1.2.174
  • Websocket extension version: 1.4.0

Platforms (REQUIRED):

  • Any

Minimal repro case project:
Websocket.zip (2.9 KB)

Logs:

ERROR:SCRIPT: /main/network.script:9: attempt to concatenate field 'error' (a nil value)
stack traceback:
	/main/network.script:9: in function </main/network.script:1>

Workaround:
Use data.message instead of data.error.

3 Likes

Thanks!
A note that it is a bit easier to keep track of issues if you report them in the extension repo.

1 Like

Added to the repo by Mathias here: https://github.com/defold/extension-websocket/issues/18

Solved in extension-websocket 1.5.0.

2 Likes