Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix logging exception which is thrown if command output contains non-ASCII characters #18

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions octoprint_gcodesystemcommands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
__license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agpl.html"
__copyright__ = "Copyright (C) 2017 Shawn Bruce - Released under terms of the AGPLv3 License"

import six

import octoprint.plugin
import time
import os
Expand Down Expand Up @@ -76,6 +78,9 @@ def hook_gcode_sending(self, comm_instance, phase, cmd, cmd_type, gcode, *args,
self._logger.exception("Error executing command ID %s: %s" % (cmd_id, e))
return (None,)

# Make sure we don't throw when logging output if it contains non-ascii characters
output = six.ensure_text(output, "utf-8", "ignore")

self._logger.debug("Command ID %s returned: %s, output=%s" % (cmd_id, r, output))
self._logger.info("Command ID %s returned: %s" % (cmd_id, r))

Expand Down Expand Up @@ -106,7 +111,7 @@ def on_settings_load(self):
data[r] = None

return data

def on_settings_save(self, data):
octoprint.plugin.SettingsPlugin.on_settings_save(self, data)
self.reload_command_definitions()
Expand All @@ -119,7 +124,7 @@ def get_template_configs(self):
def get_assets(self):
return {
"js": ["js/gcodesystemcommands.js"]
}
}

def get_update_information(self):
return dict(
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
OctoPrint
# six is already required by OctoPrint, but still add it here just in case
six
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, this shouldn't be needed since OctoPrint already depends on it.

But it also doesn't hurt , especially since we don't pin it to a specific version so there is no chance of a version conflict.