diff --git a/evidence/forms.py b/evidence/forms.py index 29876f3..fefe45a 100644 --- a/evidence/forms.py +++ b/evidence/forms.py @@ -35,12 +35,14 @@ class UploadForm(forms.Form): ).first() if exist_annotation: - raise ValidationError("error: {} exist".format(file_name)) + raise ValidationError("Error! Snapshot: {} already exists".format(file_name)) - except ValueError: - raise ValidationError("Error in parsing JSON: {}. Check for file corruption.".format(file_name)) - except Exception: - raise ValidationError("error in: {}".format(file_name)) + except json.JSONDecodeError: + raise ValidationError("Error in parsing JSON: '{}'. Check for file integrity.".format(file_name)) + except ValidationError as e: + raise e + except Exception as e: + raise ValidationError("Oops! Something went wrong in '{}': {}".format(file_name, str(e))) self.evidences.append((file_name, file_json)) diff --git a/evidence/management/commands/up_snapshots.py b/evidence/management/commands/up_snapshots.py index 2f72f71..f2dbb22 100644 --- a/evidence/management/commands/up_snapshots.py +++ b/evidence/management/commands/up_snapshots.py @@ -53,13 +53,15 @@ class Command(BaseCommand): with open(filepath, 'r') as file: content = json.loads(file.read()) path_name = save_in_disk(content, self.user.institution.name) + self.snapshots.append((content, path_name)) - except json.JSONDecodeError: - raise ValueError(f"Invalid JSON format in file {filepath}.") + except json.JSONDecodeError as e: + raise e #or we cath'em all - except Exception as e: + except Exception: raise Exception(f"Oops! Something went wrong there") + def parsing(self): for s, p in self.snapshots: try: