Instead of using a lambda for the key function, write a full function definition. Have this function catch the exception from strptime
and raise its own exception with the date string identified.
Using the suggestion from the comments to add information to the existing exception object, with guidance from https://wiki.python.org/moin/HandlingExceptions
def start_key(x):
d = None
try:
d = x["start"]
return datetime.datetime.strptime(d, "%Y%m%d-%H%M")
except Exception as e:
if d:
e.args += (d,)
raise
value["spotlight"].sort(key=start_key, reverse=True)