graphify icon indicating copy to clipboard operation
graphify copied to clipboard

`serve.py`: the "graph.json is corrupted" recovery message can never be printed (except-clause ordering)

Open Job28703 opened this issue 4 months ago • 1 comments

SECURITY.md lists this under the threat table:

| Corrupted graph.json | _load_graph() in serve.py wraps json.JSONDecodeError and prints a clear recovery message instead of crashing. |

The handler exists, but it is unreachable. In graphify/serve.py:

    except (ValueError, FileNotFoundError) as exc:
        print(f"error: {exc}", file=sys.stderr)
        sys.exit(1)
    except json.JSONDecodeError as exc:
        print(f"error: graph.json is corrupted ({exc}). Re-run /graphify to rebuild.", file=sys.stderr)
        sys.exit(1)

json.JSONDecodeError subclasses ValueError, so the first clause always wins:

>>> import json
>>> issubclass(json.JSONDecodeError, ValueError)
True

Observed behaviour with a truncated graph.json: users get the bare

error: Expecting value: line 1 column 1 (char 0)

instead of the intended graph.json is corrupted (...). Re-run /graphify to rebuild. This matters more than a cosmetic message, because the atomic-write and shrink-guard work in 0.9.18 explicitly treats a truncated graph.json as a state users need to recover from — and the recovery hint is exactly what never reaches them.

Suggested fix

Move the json.JSONDecodeError clause above the (ValueError, FileNotFoundError) clause.

How this was found

Static read of graphify/serve.py plus a local check of the exception hierarchy. No graphify process was run against a real corpus.

Job28703 avatar Jul 18 '26 17:07 Job28703

Hii I am working on fix for this, should have a PR ready soon.

HerenderKumar avatar Jul 18 '26 17:07 HerenderKumar