From 768238d72aafb42f66e7b28f701625dc5dda525c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 26 Mar 2026 17:22:52 +0000 Subject: [PATCH] fix: replace bare except clauses with specific NetworkX exceptions - graph_operations.py:244: catch nx.NetworkXNoPath instead of bare except, consistent with the same pattern in networkx_plotting.py - id_identifier.py:128: catch nx.NetworkXUnfeasible instead of bare except, which is the exception nx.topological_sort() raises for graphs containing cycles Bare except clauses mask unrelated bugs (e.g. MemoryError, KeyboardInterrupt) and make debugging harder. Both replacements preserve existing behaviour exactly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- dowhy/causal_identifier/id_identifier.py | 2 +- dowhy/utils/graph_operations.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dowhy/causal_identifier/id_identifier.py b/dowhy/causal_identifier/id_identifier.py index db8af1bff2..5ef8a515dd 100644 --- a/dowhy/causal_identifier/id_identifier.py +++ b/dowhy/causal_identifier/id_identifier.py @@ -125,7 +125,7 @@ def identify_effect_id( try: tsort_node_names = OrderedSet(list(nx.topological_sort(graph))) # topological sorting of graph nodes - except: + except nx.NetworkXUnfeasible: raise Exception("The graph must be a directed acyclic graph (DAG).") return __adjacency_matrix_identify_effect( diff --git a/dowhy/utils/graph_operations.py b/dowhy/utils/graph_operations.py index 030a0fd10a..73d6370ce5 100644 --- a/dowhy/utils/graph_operations.py +++ b/dowhy/utils/graph_operations.py @@ -241,7 +241,7 @@ def find_predecessor(i, j, g): try: path = shortest_path(u, pa, i) return pa - except: + except nx.NetworkXNoPath: pass return None