Handle KeyError in Graph class constructor

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-03-05 22:46:32 -03:00
commit 1b4f0138d2

View file

@ -320,9 +320,12 @@ class Graph:
return cls(vertices, edges, flow_id)
except KeyError as exc:
logger.exception(exc)
raise ValueError(
f"Invalid payload. Expected keys 'nodes' and 'edges'. Found {list(payload.keys())}"
) from exc
if "nodes" not in payload and "edges" not in payload:
logger.exception(exc)
raise ValueError(
f"Invalid payload. Expected keys 'nodes' and 'edges'. Found {list(payload.keys())}"
) from exc
raise ValueError(f"Error while creating graph from payload: {exc}") from exc
def __eq__(self, other: object) -> bool:
if not isinstance(other, Graph):