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] OWFile: Report errors for incorrect file formats instead of crashing #1635

Merged
merged 1 commit into from
Oct 7, 2016
Merged
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
47 changes: 27 additions & 20 deletions Orange/widgets/data/owfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,29 +257,36 @@ def browse_file(self, in_demos=False):

# Open a file, create data from it and send it over the data channel
def load_data(self):
# We need to catch any exception type since anything can happen in
# file readers
# pylint: disable=broad-except
self.editor_model.set_domain(None)
Copy link
Contributor

Choose a reason for hiding this comment

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

self.data used to be cleared in case of errors, now it is not anymore...

This is used in reports for example (maybe elsewhere too), which now report on previous data, even after trying to open something else and failing.

self.reader = self._get_reader()
if not self.reader:
self.data = None
self.send("Data", None)
self.info.setText("No data.")
return
self._update_sheet_combo()

errors = []
with catch_warnings(record=True) as warnings:
try:
data = self.reader.read()
except Exception as ex:
errors.append("An error occurred:")
errors.append(str(ex))
data = None
self.editor_model.reset()
self.warning(warnings[-1].message.args[0] if warnings else '')

if data is None:
error = None
try:
self.reader = self._get_reader()
if self.reader is None:
self.send("Data", None)
self.info.setText("No data.")
self.sheet_box.hide()
return
except Exception as ex:
error = ex

if not error:
self._update_sheet_combo()
with catch_warnings(record=True) as warnings:
try:
data = self.reader.read()
except Exception as ex:
error = ex
self.warning(warnings[-1].message.args[0] if warnings else '')

if error:
self.send("Data", None)
self.info.setText("\n".join(errors))
self.info.setText("An error occurred:\n{}".format(error))
self.editor_model.reset()
self.sheet_box.hide()
return

self.info.setText(self._describe(data))
Expand Down