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

オープン 初心者向け
#458 コメント 0 件 リアクション 0 件 担当者 1 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@dsengupta0628 がすでに取り組んでいます。

2026年11月10日 から。

  • #461 @NopeCharon による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
領域
tooling

調査の方向性

tcl/CmdUtil.tcl の with_output_to_variable から始め、issue が例として挙げている tcl/Util.tcl の proc_redirect と動作を比較します。示されている Tcl の例を使ってスコープとエラーの挙動を確認し、既存の回避策である test/set_path_margin_common.tcl も確認します。出力のリダイレクト終了後に、コマンドから呼び出し元の変数にアクセスでき、エラーが呼び出し元に伝わるようになれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Verilog
スター
658
フォーク
299
平均マージ
1日 12時間
マージ済み PR(30日)
28

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

The-OpenROAD-Project/OpenSTA のほかの issue

The-OpenROAD-Project/OpenSTA の issue をすべて見る

似ている issue

DevTools の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。