stencila/executa

fix(Client.receive): Handle malformed responses

Closed this issue ยท 1 comments

Executa will throw an error and exit if a peer responds with a malformed response. Instead, it should have a try around the JSON.parse and handle errors like other errors.

The following log is from within a Docker container that was sent a bit of Python code that the Python interpreter could not handle and which seems to have caused it to output to stdout instead of returning a JSON-RPC response with an error property (that needs to be fixed there, but that's a separate issue).

docker logs stoic_shirley 
{"time":"2019-11-18T22:36:58.983Z","tag":"executa:executor","level":2,"message":"Starting servers: stdio"}
{"time":"2019-11-18T22:37:07.017Z","tag":"executa:executor","level":2,"message":"Discovering peers"}
{"time":"2019-11-18T22:37:07.031Z","tag":"executa:serve","level":2,"message":"Added manifest at /home/guest/.stencila/executors/javascript.json"}
{"time":"2019-11-18T22:37:07.031Z","tag":"executa:serve","level":2,"message":"Added manifest at /home/guest/.stencila/executors/py.json"}
undefined:1
NFO:stencila.schema.interpreter:Not executing CodeChunk without AST: x = 
^

SyntaxError: Unexpected token N in JSON at position 0
    at JSON.parse (<anonymous>)
    at StdioClient.receive (/usr/lib/node_modules/@stencila/executa/dist/lib/base/Client.js:108:29)
    at Decoder.<anonymous> (/usr/lib/node_modules/@stencila/executa/dist/lib/stream/StreamClient.js:31:18)
    at Decoder.emit (events.js:210:5)
    at addChunk (/usr/lib/node_modules/@stencila/executa/node_modules/readable-stream/lib/_stream_readable.js:297:12)
    at readableAddChunk (/usr/lib/node_modules/@stencila/executa/node_modules/readable-stream/lib/_stream_readable.js:279:11)
    at Decoder.Readable.push (/usr/lib/node_modules/@stencila/executa/node_modules/readable-stream/lib/_stream_readable.js:240:10)
    at Decoder.Transform.push (/usr/lib/node_modules/@stencila/executa/node_modules/readable-stream/lib/_stream_transform.js:139:32)
    at Decoder._push (/usr/lib/node_modules/@stencila/executa/node_modules/length-prefixed-stream/decode.js:29:8)
    at Decoder._parseMessage (/usr/lib/node_modules/@stencila/executa/node_modules/length-prefixed-stream/decode.js:58:12)

๐ŸŽ‰ This issue has been resolved in version 0.14.2 ๐ŸŽ‰

The release is available on:

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€