src/eric7/MicroPython/MicroPythonFileManagerWidget.py

branch
eric7
changeset 10236
c270c9501f1c
parent 10143
bf84513859ca
child 10388
a34ce7f42e8b
--- a/src/eric7/MicroPython/MicroPythonFileManagerWidget.py	Tue Oct 10 16:28:45 2023 +0200
+++ b/src/eric7/MicroPython/MicroPythonFileManagerWidget.py	Tue Oct 10 18:05:17 2023 +0200
@@ -407,10 +407,20 @@
                 self.__fileManager.cd(name[:-1])
             else:
                 data = self.__fileManager.getData(name)
-                text = data.decode(encoding="utf-8")
-                ericApp().getObject("ViewManager").newEditorWithText(
-                    text, fileName="device:{0}".format(name)
-                )
+                try:
+                    text = data.decode(encoding="utf-8")
+                    ericApp().getObject("ViewManager").newEditorWithText(
+                        text, fileName="device:{0}".format(name)
+                    )
+                except UnicodeDecodeError:
+                    EricMessageBox.warning(
+                        self,
+                        self.tr("Open Device File"),
+                        self.tr(
+                            "<p>The file <b>{0}</b> does not contain Unicode text.</p>"
+                        ).format(name),
+                    )
+                    return
 
     @pyqtSlot()
     def on_deviceFileTreeWidget_itemSelectionChanged(self):

eric ide

mercurial