better error messages
This commit is contained in:
parent
3763124440
commit
80083caf99
|
@ -35,11 +35,19 @@ class UploadForm(forms.Form):
|
||||||
).first()
|
).first()
|
||||||
|
|
||||||
if exist_annotation:
|
if exist_annotation:
|
||||||
raise ValidationError("error: {} exist".format(file_name))
|
raise ValidationError(
|
||||||
|
_("The snapshot already exists"),
|
||||||
except Exception:
|
code="duplicate_snapshot",
|
||||||
raise ValidationError("error in: {}".format(file_name))
|
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))
|
self.evidences.append((file_name, file_json))
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -56,14 +56,14 @@ class Command(BaseCommand):
|
||||||
|
|
||||||
except json.JSONDecodeError as e:
|
except json.JSONDecodeError as e:
|
||||||
logger.error("JSON decode error in file %s: %s", filepath, 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:
|
except FileNotFoundError as e:
|
||||||
logger.error("File not found: %s", filepath)
|
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
|
#or we cath'em all
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception("Unexpected error when opening file %s: %s", filepath, 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):
|
def parsing(self):
|
||||||
for s, p in self.snapshots:
|
for s, p in self.snapshots:
|
||||||
|
|
Loading…
Reference in New Issue