fix: resolve key error for visualization, handle ValueError for jedi … (#509)
…and move duplicate edge information to debug log <!-- .github/pull_request_template.md --> ## Description Fix visualization bug Handle ValueError for CodeGraph Move debug information from print to debug logs ## DCO Affirmation I affirm that all code in every commit of this pull request conforms to the terms of the Topoteretes Developer Certificate of Origin <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Enhanced error handling across several modules to ensure smoother operation when unexpected conditions occur. - Updated diagnostic and logging mechanisms to provide more robust system feedback and reduce potential disruptions. - Improved robustness in the deletion of properties to prevent runtime errors related to missing keys. - Added additional exception handling for better analysis of code entities. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
parent
2e842652be
commit
6be6b3d222
3 changed files with 20 additions and 8 deletions
|
|
@ -1,5 +1,4 @@
|
||||||
import numpy as np
|
import logging
|
||||||
|
|
||||||
from typing import List, Dict, Union
|
from typing import List, Dict, Union
|
||||||
|
|
||||||
from cognee.exceptions import InvalidValueError
|
from cognee.exceptions import InvalidValueError
|
||||||
|
|
@ -8,7 +7,8 @@ from cognee.infrastructure.databases.graph.graph_db_interface import GraphDBInte
|
||||||
from cognee.modules.graph.cognee_graph.CogneeGraphElements import Node, Edge
|
from cognee.modules.graph.cognee_graph.CogneeGraphElements import Node, Edge
|
||||||
from cognee.modules.graph.cognee_graph.CogneeAbstractGraph import CogneeAbstractGraph
|
from cognee.modules.graph.cognee_graph.CogneeAbstractGraph import CogneeAbstractGraph
|
||||||
import heapq
|
import heapq
|
||||||
import asyncio
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class CogneeGraph(CogneeAbstractGraph):
|
class CogneeGraph(CogneeAbstractGraph):
|
||||||
|
|
@ -40,7 +40,7 @@ class CogneeGraph(CogneeAbstractGraph):
|
||||||
edge.node1.add_skeleton_edge(edge)
|
edge.node1.add_skeleton_edge(edge)
|
||||||
edge.node2.add_skeleton_edge(edge)
|
edge.node2.add_skeleton_edge(edge)
|
||||||
else:
|
else:
|
||||||
print(f"Edge {edge} already exists in the graph.")
|
logger.debug(f"Edge {edge} already exists in the graph.")
|
||||||
|
|
||||||
def get_node(self, node_id: str) -> Node:
|
def get_node(self, node_id: str) -> Node:
|
||||||
return self.nodes.get(node_id, None)
|
return self.nodes.get(node_id, None)
|
||||||
|
|
|
||||||
|
|
@ -21,10 +21,19 @@ async def cognee_network_visualization(graph_data):
|
||||||
node_info["id"] = str(node_id)
|
node_info["id"] = str(node_id)
|
||||||
node_info["color"] = color_map.get(node_info.get("pydantic_type", "default"), "#D3D3D3")
|
node_info["color"] = color_map.get(node_info.get("pydantic_type", "default"), "#D3D3D3")
|
||||||
node_info["name"] = node_info.get("name", str(node_id))
|
node_info["name"] = node_info.get("name", str(node_id))
|
||||||
del node_info[
|
|
||||||
"updated_at"
|
try:
|
||||||
] #:TODO: We should decide what properties to show on the nodes and edges, we dont necessarily need all.
|
del node_info[
|
||||||
del node_info["created_at"]
|
"updated_at"
|
||||||
|
] #:TODO: We should decide what properties to show on the nodes and edges, we dont necessarily need all.
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
try:
|
||||||
|
del node_info["created_at"]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
nodes_list.append(node_info)
|
nodes_list.append(node_info)
|
||||||
G.add_node(node_id, **node_info)
|
G.add_node(node_id, **node_info)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,9 @@ def _update_code_entity(script: jedi.Script, code_entity: Dict[str, any]) -> Non
|
||||||
except AssertionError as e:
|
except AssertionError as e:
|
||||||
# TODO: See if there is a way to handle AttributeError properly
|
# TODO: See if there is a way to handle AttributeError properly
|
||||||
logger.error(f"Failed to analyze code entity {code_entity['name']}: {e}")
|
logger.error(f"Failed to analyze code entity {code_entity['name']}: {e}")
|
||||||
|
except ValueError as e:
|
||||||
|
# TODO: See if there is a way to handle ValueError properly
|
||||||
|
logger.error(f"Failed to analyze code entity {code_entity['name']}: {e}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# logging.warning(f"Failed to analyze code entity {code_entity['name']}: {e}")
|
# logging.warning(f"Failed to analyze code entity {code_entity['name']}: {e}")
|
||||||
logger.error(f"Failed to analyze code entity {code_entity['name']}: {e}")
|
logger.error(f"Failed to analyze code entity {code_entity['name']}: {e}")
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue