From 724f9ce0106a598421a57c3bf24efd3579fd28f3 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Tue, 19 Apr 2016 16:08:47 +0200 Subject: [PATCH] Return None if config file wasn't correct This was actually specified in the original function description. Contributes to issue CURA-844. --- .../VersionUpgrade/VersionUpgrade21to22/MachineInstance.py | 5 ++++- plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py index 2291adf92b..1a6f7b9da9 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py @@ -13,7 +13,10 @@ import io #To write config files to strings as if they were files. # \return A machine instance instance, or None if the file format is # incorrect. def importVersion1(serialised): - return MachineInstance(serialised) + try: + return MachineInstance(serialised) + except configparser.Error, SettingsError.InvalidFormatError, SettingsError.InvalidVersionError: + return None ## A representation of a machine instance used as intermediary form for # conversion from one format to the other. diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py index 8fd48745b1..52180b72e0 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py @@ -12,7 +12,10 @@ import io #To write config files to strings as if they were files. # \param serialised The serialised form of a profile in version 1. # \return A profile instance, or None if the file format is incorrect. def importVersion1(serialised): - return Profile(serialised) + try: + return Profile(serialised) + except configparser.Error, SettingsError.InvalidFormatError, SettingsError.InvalidVersionError: + return None ## A representation of a profile used as intermediary form for conversion from # one format to the other.