Skip to content

Commit

Permalink
wrap a try/catch around metadata parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
tabatkins committed Dec 21, 2023
1 parent 70d45df commit 5845cb7
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions bikeshed/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,20 @@ def addData(self, key: str, val: str, lineNum: str | int | None = None) -> Metad

if key not in ("ED", "TR", "URL"):
key = key.title()
self.allData[key].append(val)

if key not in knownKeys:
m.die(f'Unknown metadata key "{key}". Prefix custom keys with "!".', lineNum=lineNum)
return self
md = knownKeys[key]

val = md.parse(key, val, lineNum=lineNum)
md = knownKeys[key]
try:
parsedVal = md.parse(key, val, lineNum=lineNum)
except Exception as e:
m.die(f"Error while parsing '{key}' metadata value:\n {val}\n{e}")
return self

self.addParsedData(key, val)
self.allData[key].append(val)
self.addParsedData(key, parsedVal)
return self

def addParsedData(self, key: str, val: t.Any) -> MetadataManager:
Expand Down

0 comments on commit 5845cb7

Please sign in to comment.