🥅 Validate additional data from plugins at source
That way it won't even enter the state data if it's not JSON compliant, that's better than no longer being able to send any state reports just because one plugin is sending broken data. Closes #3875
This commit is contained in:
1 parent
cfaeaba39c
commit
dc269846d1
3 files changed
+19
-8
No files matched your search
@@ -18,6 +18,7 @@ import time
|
||||
from frozendict import frozendict
|
||||
from past.builtins import basestring, long
|
||||
|
||||
import octoprint.util.json
|
||||
from octoprint import util as util
|
||||
from octoprint.events import Events, eventManager
|
||||
from octoprint.filemanager import FileDestinations, NoSuchStorage, valid_file_type
|
||||
@@ -272,7 +273,13 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
try:
|
||||
additional = hook(initial=initial)
|
||||
if additional and isinstance(additional, dict):
|
||||
octoprint.util.json.dump({name: additional})
|
||||
plugin_data[name] = additional
|
||||
except ValueError:
|
||||
self._logger.exception(
|
||||
"Invalid additional data from plugin {}".format(name),
|
||||
extra={"plugin": name},
|
||||
)
|
||||
except Exception:
|
||||
self._logger.exception(
|
||||
"Error while retrieving additional data from plugin {}, blacklisting it for further loops".format(
|
||||
|
||||
@@ -5,7 +5,6 @@ __author__ = "Gina Häußge <osd@foosel.net>"
|
||||
__license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agpl.html"
|
||||
__copyright__ = "Copyright (C) 2014 The OctoPrint Project - Released under terms of the AGPLv3 License"
|
||||
|
||||
import json
|
||||
import logging
|
||||
import threading
|
||||
import time
|
||||
@@ -27,7 +26,7 @@ from octoprint.access.permissions import Permissions
|
||||
from octoprint.access.users import LoginStatusListener
|
||||
from octoprint.events import Events
|
||||
from octoprint.settings import settings
|
||||
from octoprint.util.json import JsonEncoding
|
||||
from octoprint.util.json import dump as json_dump
|
||||
|
||||
|
||||
class ThreadSafeSession(octoprint.vendor.sockjs.tornado.session.Session):
|
||||
@@ -67,12 +66,7 @@ class ThreadSafeSession(octoprint.vendor.sockjs.tornado.session.Session):
|
||||
class JsonEncodingSessionWrapper(wrapt.ObjectProxy):
|
||||
def send_message(self, msg, stats=True, binary=False):
|
||||
self.send_jsonified(
|
||||
json.dumps(
|
||||
octoprint.vendor.sockjs.tornado.util.bytes_to_str(msg),
|
||||
separators=(",", ":"),
|
||||
default=JsonEncoding.encode,
|
||||
allow_nan=False,
|
||||
),
|
||||
json_dump(octoprint.vendor.sockjs.tornado.util.bytes_to_str(msg)),
|
||||
stats,
|
||||
)
|
||||
|
||||
|
||||
@@ -6,12 +6,22 @@ __copyright__ = "Copyright (C) 2018 The OctoPrint Project - Released under terms
|
||||
|
||||
|
||||
import collections
|
||||
import json
|
||||
|
||||
import frozendict
|
||||
|
||||
from octoprint.util import to_unicode
|
||||
|
||||
|
||||
def dump(obj):
|
||||
return json.dumps(
|
||||
obj,
|
||||
separators=(",", ":"),
|
||||
default=JsonEncoding.encode,
|
||||
allow_nan=False,
|
||||
)
|
||||
|
||||
|
||||
class JsonEncoding(object):
|
||||
|
||||
encoders = collections.OrderedDict()
|
||||
|
||||
Reference in new issue
Block a user