bugfix/parsing_error #22

Open
rskthomas wants to merge 5 commits from bugfix/parsing_error into main
3 changed files with 22 additions and 8 deletions

View File

@ -58,7 +58,7 @@
<div class="col-lg-9 col-md-8">{{ object.type }}</div>
</div>
{% if object.is_websnapshot %}
{% if object.is_websnapshot and object.last_user_evidence %}
{% for k, v in object.last_user_evidence %}
<div class="row mb-3">
<div class="col-lg-3 col-md-4 label">{{ k }}</div>

View File

@ -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))

View File

@ -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):
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: