Fix an issue with unhandled warnings from PIO Core when calling it internally // Resolved #2727

This commit is contained in:
Ivan Kravets
2019-07-03 15:10:37 +03:00
parent dc07ea56d2
commit 7c6fabaee2
2 changed files with 21 additions and 2 deletions

View File

@@ -19,6 +19,7 @@ import os
import sys
from io import BytesIO, StringIO
import click
import jsonrpc # pylint: disable=import-error
from twisted.internet import threads # pylint: disable=import-error
@@ -102,7 +103,22 @@ class PIOCoreRPC(object):
text = ("%s\n\n%s" % (out, err)).strip()
if code != 0:
raise Exception(text)
return json.loads(out) if json_output else text
if not json_output:
return text
try:
return json.loads(out)
except ValueError as e:
click.secho("%s => `%s`" % (e, out), fg="red", err=True)
# if PIO Core prints unhandled warnings
for line in out.split("\n"):
line = line.strip()
if not line:
continue
try:
return json.loads(line)
except ValueError:
pass
raise e
@staticmethod
def _call_errback(failure):