Skip to content

Commit

Permalink
fix(cff): error handling on invalid yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdoret committed Feb 1, 2024
1 parent db81df7 commit ff6bd5d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions gimie/parsers/cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

from rdflib.term import URIRef

from gimie import logger
from gimie.graph.namespaces import SDO
from gimie.parsers.abstract import Parser, Property

Expand Down Expand Up @@ -100,11 +101,15 @@ def get_cff_doi(data: bytes) -> Optional[str]:
"""

cff = yaml.safe_load(data.decode())
try:
cff = yaml.safe_load(data.decode())
except yaml.scanner.ScannerError:
logger.warn("cannot read CITATION.cff, skipped.")
return None

try:
doi = cff["doi"]
except KeyError:
except (KeyError, TypeError):
return None

return doi_to_url(doi)

0 comments on commit ff6bd5d

Please sign in to comment.