lang-core: excess-args is an error even when the element renders in full, and doesn't say what was dropped

Aperta Adatta ai principianti
#1,711 0 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
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
compilers

Direzione di ricerca

Inizia in packages/lang-core/src/parser/validation.ts da pushValidationIssue, che oggi imposta severity: "warning" solo per il fallback no-root, e leggi il commento di documentazione di severity in ValidationError a cui fa riferimento. Poi trova il punto di chiamata che emette excess-args e calcola il conteggio, e verifica se i nodi degli argomenti scartati sono ancora nello scope in quel punto così da poterli allegare all'issue. Esegui i test del parser di lang-core con la riproduzione dell'issue (Stack/Table con un null finale) per confermare il caso di warning e che un argomento scartato non nullo continua a generare un errore. È completato quando entrambi i casi sono distinguibili solo da meta.errors.

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

Descrizione

bug package: lang-core

Describe the bug
When a component is called with more arguments than its signature, excess-args is reported as a plain error (no severity). The extra arguments are dropped and the element still renders in full. By the severity doc comment on ValidationError ("warning" when the program still renders), that looks like a warning. As it stands, a host that shows errors to people reports a failure under an element that rendered correctly.

The error also doesn't say what was dropped. A host can't tell a harmless trailing null apart from a real loss, such as a value the model meant for an argument that doesn't exist. Both cases give the same error.

To Reproduce

root = Stack([tbl])
tbl = Table([Col("Owner", ["Ana", "Ben"]), Col("Task", ["Draft", "Review"])], null)

Parse it with createParser(openuiLibrary.toJSONSchema(), "Stack") (@openuidev/lang-core 1.1.1, @openuidev/react-ui 0.18.9, where the signature is Table(columns: Col[])):

  • meta.errors is [{ code: "excess-args", component: "Table", statementId: "tbl", message: "Table takes 1 arg(s), got 2 (1 excess dropped)" }], with no severity.
  • root is not null, and the Table has both columns and all rows.

I saw this from a model writing a table in a chat reply: it added a trailing null. pushValidationIssue in packages/lang-core/src/parser/validation.ts sets severity: "warning" only for the no-root fallback, and that is the same on main today.

Expected behavior

  • When every dropped argument is null, excess-args is marked severity: "warning", because nothing is lost.
  • When a dropped argument has a value, it stays an error, because something the model wrote is not shown. It would help if the error carried the dropped arguments (or at least whether any of them was non-null), so hosts and autofix loops can tell the two cases apart without re-parsing.

Additional context
For now I work around it by re-tokenizing the statement named by statementId (tokenize, split, parseExpression, walkAST) and checking whether the dropped arguments are all Null nodes.

Thanks,
Sebastian

Lingua principale
TypeScript
Stelle
10k
Fork
698
Merge medio
1g 7h
PR unite (30g)
134

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

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 thesysdev/openui

Tutte le issue di thesysdev/openui

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.