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

canvasmain: More informative message for unsupported format #202

Merged
Merged
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
14 changes: 14 additions & 0 deletions orangecanvas/application/canvasmain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,20 @@ def load_scheme(self, filename):
return
f.seek(0, os.SEEK_SET)
new_scheme = self.new_scheme_from_contents_and_path(f, filename)
except readwrite.UnsupportedFormatVersionError:
mb = QMessageBox(
self, windowTitle=self.tr("Error"),
icon=QMessageBox.Critical,
text=self.tr("Unsupported format version"),
informativeText=self.tr(
"The file was saved in a format not supported by this "
"application."
),
detailedText="".join(traceback.format_exc()),
)
mb.setAttribute(Qt.WA_DeleteOnClose)
mb.setWindowModality(Qt.WindowModal)
mb.open()
except Exception as err:
mb = QMessageBox(
parent=self, windowTitle=self.tr("Error"),
Expand Down
12 changes: 12 additions & 0 deletions orangecanvas/application/tests/test_mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,18 @@ def query(names):
return_value=QDialog.Rejected):
w.install_requirements(["uber-package-shiny", "spasm"])

def test_load_unsupported_format(self):
w = self.w
workflow = w.current_document().scheme()
with temp_named_file('<scheme version="99.9"></scheme>') as fname, \
patch.object(QMessageBox, "open", lambda self: None):
w.load_scheme(fname)
self.assertIs(w.current_document().scheme(), workflow)
dlg = w.findChild(QMessageBox)
self.assertIsNotNone(dlg)
self.assertIn("99.9", dlg.detailedText())
dlg.done(QMessageBox.Ok)


TEST_OWS = b"""\
<?xml version='1.0' encoding='utf-8'?>
Expand Down
17 changes: 13 additions & 4 deletions orangecanvas/scheme/readwrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,30 +321,39 @@ def parse_ows_etree_v_2_0(tree):
)


class InvalidFormatError(ValueError):
pass


class UnsupportedFormatVersionError(ValueError):
pass


def parse_ows_stream(stream):
# type: (Union[AnyStr, IO]) -> _scheme
doc = parse(stream)
scheme_el = doc.getroot()
if scheme_el.tag != "scheme":
raise ValueError(
raise InvalidFormatError(
"Invalid Orange Workflow Scheme file"
)
version = scheme_el.get("version", None)
if version is None:
# Check for "widgets" tag - old Orange<2.7 format
if scheme_el.find("widgets") is not None:
raise ValueError(
raise UnsupportedFormatVersionError(
"Cannot open Orange Workflow Scheme v1.0. This format is no "
"longer supported"
)
else:
raise ValueError(
raise InvalidFormatError(
"Invalid Orange Workflow Scheme file (missing version)."
)
if version in {"2.0", "2.1"}:
return parse_ows_etree_v_2_0(doc)
else:
raise ValueError()
raise UnsupportedFormatVersionError(
f"Unsupported format version {version}")


def resolve_replaced(scheme_desc: _scheme, registry: WidgetRegistry) -> _scheme:
Expand Down