Deeply nested JSON input to the CLI exits 1 unstructured instead of invalid_argument

Aperta Adatta ai principianti
#401 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
74/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
cli

Direzione di ricerca

Inizia in src/selfgraph/runtime.py, da parse_json, e ispeziona la gestione delle eccezioni. Poi segui il modo in cui cli.main segnala ValidationError. Controlla i test esistenti per il JSON malformato e aggiungi la copertura per input profondamente annidati. Il lavoro è completato quando la CLI restituisce il codice di uscita 2 con un errore strutturato invalid_argument per i casi di riproduzione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

approved-for-pr area: cli-mcp area: errors bug effort: S P3

Summary

A deeply nested JSON value passed to the CLI (as a --prop/--evidence value, an insert facts file, or inline --schema/--prompts) exits with code 1 and an unstructured error: Stack overflow ... message, rather than exit 2 with a structured invalid_argument error. parse_json catches only ValueError, but a deeply nested document makes json.loads raise a RecursionError, which is not a ValueError.

Reproduction (0.2.2)

Create a value that is 100000 nested [:

DEEP=$(python3 -c 'print("["*100000)')
selfgraph --store kuzu --uri g.kuzu entity create --name a --type T --prop "k=$DEEP"

Observed: exit code 1, error: Stack overflow (used 8144 kB) while decoding a JSON array ..., with no error[code], no field, and no hint. The same happens with an insert facts file of 200000 [ characters and with inline --schema/--prompts JSON.

Expected: exit code 2 with a structured error[invalid_argument], as other malformed JSON produces, since the input is invalid.

Cause

parse_json in src/selfgraph/runtime.py (around line 153) catches only ValueError:

try:
    return json.loads(text, parse_constant=_reject_constant)
except ValueError as exc:
    raise ValidationError(f"invalid JSON{where}: {exc}") from exc

A deeply nested document raises RecursionError (a RuntimeError subclass), which escapes the except ValueError and is then caught by cli.main's RuntimeError branch, which prints error: <message> with exit 1 and no code. This is the same class of gap as #347 (a reader catching too narrow an exception type). It also defeats the "parse as JSON, else keep as text" fallback used for --prop, so the value cannot fall through to text.

Expected

parse_json treats a too-deeply-nested document as invalid JSON and raises ValidationError (invalid_argument), so the CLI exits 2 with a structured error for this input like any other malformed JSON.

Lingua principale
TypeScript
Stelle
173
Fork
58
Merge medio
6h
PR unite (30g)
120

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di hydra-db/selfgraph

Tutte le issue di hydra-db/selfgraph

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.