Parsing error handling and MAC retrieval on new snapshots #27

Merged
pedro merged 12 commits from pr_25 into main 2024-11-12 13:57:05 +00:00
2 changed files with 17 additions and 9 deletions
Showing only changes of commit eb81b65e5b - Show all commits

View File

@ -35,11 +35,19 @@ class UploadForm(forms.Form):
).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

View File

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