with_output_to_variable runs its commands outside the caller's scope and hides errors

Aperta Adatta ai principianti
#458 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@dsengupta0628 ci sta già lavorando.

Dal 10/11/2026.

  • #461 di @NopeCharon — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Ambito
tooling

Direzione di ricerca

Inizia con with_output_to_variable in tcl/CmdUtil.tcl e confrontane il comportamento con proc_redirect in tcl/Util.tcl, che l’issue indica come esempio. Verifica l’ambito e il comportamento degli errori con gli esempi Tcl mostrati, compreso test/set_path_margin_common.tcl come soluzione temporanea esistente. Il lavoro è terminato quando i comandi possono accedere alle variabili del chiamante e i loro errori raggiungono il chiamante dopo la fine del reindirizzamento dell’output.

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

Descrizione

with_output_to_variable evaluates its commands inside its own proc, not in the caller's scope, and it swallows any error they raise.

Inside a proc, a body that uses the proc's local variables fails, but the failure is hidden: the output variable is just empty. For example:

proc capture { pin } {
  with_output_to_variable out { report_edges -from [get_pins $pin] }
  return $out
}
puts "<[capture reg1/CK]>"

This prints <> with no error, because $pin doesn't exist in with_output_to_variable's frame. At the top level the body can't see local variables either, and variables it sets are lost:

with_output_to_variable out { set x 1; report_units }
puts $x   ;# can't read "x": no such variable

Errors are caught and returned as the command's result:

puts [catch {with_output_to_variable v { report_units; error boom }} msg]
# prints 0; msg is "boom"

Callers can't tell that the commands failed and that the captured output is incomplete. Some tests work around the scope problem. For example, test/set_path_margin_common.tcl builds the body with [list report_checks {*}$args -format json] so that $args is substituted before the call.

parallaxsw/OpenSTA master has the same code.

Cause

tcl/CmdUtil.tcl:

proc with_output_to_variable { var_name args } {
  upvar 1 $var_name var
  set body [lindex $args 0]
  sta::redirect_string_begin;
  catch $body ret
  set var [sta::redirect_string_end]
  return $ret
}

catch $body runs the body in the proc's frame, and the catch result code is discarded. The body should be run with uplevel 1, and an error should be re-raised once the redirection has ended, as proc_redirect in tcl/Util.tcl already does.

Lingua principale
Verilog
Stelle
655
Fork
296
Merge medio
1g 12h
PR unite (30g)
28

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 The-OpenROAD-Project/OpenSTA

Tutte le issue di The-OpenROAD-Project/OpenSTA

Issue simili

Altre issue su DevTools

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.