[docs]classPelicanError(Exception):"""Base class for exceptions from within this project"""
[docs]classGoogleDriveError(PelicanError):""" Raised if an error occurs interacting with a Google API. :param reason: the error message """def__init__(self,reason:str):self.args=(reason,)self.reason=reasondef__str__(self)->str:returnf"Google Drive Error: {self.reason}"
[docs]classTagError(PelicanError):""" Base class for exceptions related to tags. :param reason: the error message :param full_tag: the tag as extracted from the template :param template_id: the file ID of the template in Google Docs """def__init__(self,reason:str,full_tag:Optional[str]=None,template_id:Optional[str]=None):self.args=(reason,)self.reason=reasonself.full_tag=full_tagself.template_id=template_id
[docs]deffill(self,full_tag:str,template_id:str)->"TagError":""" Add metadata to the exception to assist in debugging. :param full_tag: the tag as extracted from the template :param template_id: the file ID of the template in Google Docs """ifself.full_tagisNone:self.full_tag=full_tagifself.template_idisNone:self.template_id=template_idreturnself
[docs]defas_dict(self)->Dict[str,Optional[str]]:""" Return the exception as a dictionary (e.g. to serialize as JSON for the browser). """return{"reason":self.reason,"full_tag":self.full_tag,"template_id":self.template_id,}
[docs]classTagSyntaxError(TagError):"""Raised if a tag is malformed."""
[docs]classUnknownTagError(TagError):"""Raised if a tag's name is unrecognized."""
[docs]classTagArgumentError(TagError):"""Raised if a tag's argument is invalid."""
[docs]classMissingArgumentError(TagError):"""Raised if a tag's argument is missing."""
[docs]classCheckNotComputedError(PelicanError):"""Raised if a check cannot be computed. The error message should be the check's name."""