Skip to content

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

Description

@Job28703

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions