tirth8205/code-review-graph · warning · ValueError

Graph is empty, nothing to export

Error message

Graph is empty, nothing to export

What it means

export_svg() builds a networkx graph from stored nodes/edges and refuses to render when zero nodes survive — drawing an empty graph is meaningless and usually signals wrong filters or a wrong database.

Source

Thrown at code_review_graph/exports.py:391

    import networkx as nx

    data = export_graph_data(store)
    nodes_data = data["nodes"]
    edges_data = data["edges"]

    nxg: nx.DiGraph = nx.DiGraph()  # type: ignore[type-arg]
    for n in nodes_data:
        nxg.add_node(
            n["qualified_name"],
            label=n.get("name", ""),
            kind=n.get("kind", ""),
        )
    for e in edges_data:
        if e["source"] in nxg and e["target"] in nxg:
            nxg.add_edge(e["source"], e["target"])

    if nxg.number_of_nodes() == 0:
        raise ValueError("Graph is empty, nothing to export")

    # Color by kind
    kind_colors = {
        "File": "#6c757d",
        "Class": "#0d6efd",
        "Function": "#198754",
        "Type": "#ffc107",
        "Test": "#dc3545",
    }
    colors = [
        kind_colors.get(
            nxg.nodes[n].get("kind", ""), "#adb5bd"
        )
        for n in nxg.nodes()
    ]

    fig, ax = plt.subplots(1, 1, figsize=(16, 12))
    pos = nx.spring_layout(

View on GitHub (pinned to b58668751a)

Solutions

  1. Run the indexer to populate the graph first
  2. Check you're reading the correct database file
  3. Relax or fix any node filters applied before export

Example fix

# before
export_svg(empty_store, out.svg)
# after
# build the graph first, then:
export_svg(populated_store, out.svg)
Defensive patterns

Strategy: validation

Validate before calling

count = graph_store.node_count() if hasattr(graph_store, "node_count") else len(list(graph_store.get_all_nodes()))
if count == 0:
    raise RuntimeError("graph empty; index the repo before exporting")

Type guard

def graph_is_exportable(store) -> bool:
    return len(list(store.get_all_nodes())) > 0

Try / catch

try:
    export_svg(store, path)
except ValueError as e:
    if "nothing to export" in str(e):
        log.warning("skip export; graph is empty")
    else:
        raise

Prevention

When it happens

Trigger: Calling export_svg() on an empty graph store, or when all nodes are filtered out before export (edges to missing nodes are also dropped).

Common situations: Exporting before indexing anything, pointing at a fresh/wrong .db, or filter conditions that exclude every node.

Related errors


AI-assisted analysis of tirth8205/code-review-graph@b58668751a (2026-08-28). Data as JSON: /api/errors/6a33cff28e8d02ae. Report an issue: GitHub.