diff --git a/device/templates/details.html b/device/templates/details.html
index 8477948..80c5a21 100644
--- a/device/templates/details.html
+++ b/device/templates/details.html
@@ -58,7 +58,7 @@
{{ k }}
diff --git a/evidence/forms.py b/evidence/forms.py
index dab7a60..fefe45a 100644
--- a/evidence/forms.py
+++ b/evidence/forms.py
@@ -35,10 +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 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 69ac134..f2dbb22 100644
--- a/evidence/management/commands/up_snapshots.py
+++ b/evidence/management/commands/up_snapshots.py
@@ -37,6 +37,8 @@ class Command(BaseCommand):
elif os.path.isdir(path):
self.read_directory(path)
+ else:
+ raise ValueError(f"The path {path} is neither a file nor a directory")
self.parsing()
@@ -47,10 +49,18 @@ class Command(BaseCommand):
self.open(filepath)
def open(self, filepath):
- 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))
+ try:
+ 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 as e:
+ raise e
+ #or we cath'em all
+ except Exception:
+ raise Exception(f"Oops! Something went wrong there")
+
def parsing(self):
for s, p in self.snapshots: