Skip to content

cluster-only crashes with FileNotFoundError if graphify-out/ doesn't exist before invocation #934

Closed

Description

@neo1777

Surfaced while testing v0.8.11 on #919. One-line fix; opening as a standalone issue rather than commenting on the closed #919 thread.

Reproducer

$ rm -rf graphify-out
$ graphify cluster-only . --graph some/other/path/graph.json --exclude-hubs 99
Loading existing graph...
Graph: 1501 nodes, 2200 edges
Re-clustering...
Traceback (most recent call last):
  ...
  File ".../graphify/__main__.py", line 1827, in main
    (out / "GRAPH_REPORT.md").write_text(report, encoding="utf-8")
  ...
FileNotFoundError: [Errno 2] No such file or directory: 'graphify-out/GRAPH_REPORT.md'

Root cause

On v8 HEAD (__main__.py SHA 895f626, line 1827):

(out / "GRAPH_REPORT.md").write_text(report, encoding="utf-8")

out is dereferenced without first being ensured to exist. The pattern out.mkdir(parents=True, exist_ok=True) is used correctly elsewhere in the same file at 20 different sites — including __main__.py:2935 where the very same identifier out is created before being written to. So this looks like an asymmetry between the extract codepath (creates out first) and the cluster-only codepath (assumes out already exists), rather than a design choice.

The crash is reachable any time a user renames or deletes graphify-out/ before re-running cluster-only — a natural workflow for archiving a previous run before re-clustering with new flags (the scenario that surfaced it). Related precedent: #422 (cluster-only skipping detect-phase setup) showed the same general pattern.

Suggested fix

One line, right before the first write into out:

out.mkdir(parents=True, exist_ok=True)
(out / "GRAPH_REPORT.md").write_text(report, encoding="utf-8")

Workaround in the meantime

mkdir -p graphify-out && graphify cluster-only ...

Environment

Happy to send a PR if useful.

Activity

  1. safishamsi commented on May 18, 2026

    @safishamsi
    Member

    Yes please send me a pr I'm happy to merge it

  2. neo1777 commented on May 18, 2026

    @neo1777
    ContributorAuthor

    Thanks! Will send the PR tomorrow evening CET — first thing after work.

  3. safishamsi commented on May 20, 2026

    @safishamsi
    Member

    Fixed in the commit pushed to v8. now creates immediately after computing the output path, before any read or write. Regression test added in . Will ship in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions