Parsing error handling and MAC retrieval on new snapshots #27
|
@ -33,13 +33,21 @@ class UploadForm(forms.Form):
|
|||
exist_annotation = Annotation.objects.filter(
|
||||
uuid=file_json['uuid']
|
||||
).first()
|
||||
|
||||
|
||||
if exist_annotation:
|
||||
raise ValidationError("error: {} exist".format(file_name))
|
||||
|
||||
except Exception:
|
||||
raise ValidationError("error in: {}".format(file_name))
|
||||
|
||||
raise ValidationError(
|
||||
_("The snapshot already exists"),
|
||||
code="duplicate_snapshot",
|
||||
params={"file_name": file_name},
|
||||
)
|
||||
|
||||
#Caught any error and display it as Validation Error so the Form handles it
|
||||
except Exception as e:
|
||||
raise ValidationError(
|
||||
_("Error on '%(file_name)s': %(error)s"),
|
||||
code="error",
|
||||
params={"file_name": file_name, "error": getattr(e, 'message', str(e))},
|
||||
)
|
||||
self.evidences.append((file_name, file_json))
|
||||
|
||||
return True
|
||||
|
|
|
@ -56,14 +56,14 @@ class Command(BaseCommand):
|
|||
|
||||
except json.JSONDecodeError as e:
|
||||
logger.error("JSON decode error in file %s: %s", filepath, e)
|
||||
raise ValueError(f"Invalid JSON format in file {filepath}") from e
|
||||
raise ValueError(f"Invalid JSON format in file. Check for file integrity.") from e
|
||||
except FileNotFoundError as e:
|
||||
logger.error("File not found: %s", filepath)
|
||||
raise FileNotFoundError(f"File not found: {filepath}") from e
|
||||
raise FileNotFoundError(f"File not found") from e
|
||||
#or we cath'em all
|
||||
except Exception as e:
|
||||
logger.exception("Unexpected error when opening file %s: %s", filepath, e)
|
||||
raise Exception(f"Unexpected error when opening file {filepath}") from e
|
||||
raise Exception(f"Unexpected error when opening file") from e
|
||||
|
||||
def parsing(self):
|
||||
for s, p in self.snapshots:
|
||||
|
|
Loading…
Reference in a new issue