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

Đang mở Phù hợp với người mới
#458 0 bình luận 0 reaction 1 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@dsengupta0628 đang làm issue này rồi.

Từ ngày 10/11/2026.

  • #461 của @NopeCharon — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Lĩnh vực
tooling

Hướng nghiên cứu

Bắt đầu với with_output_to_variable trong tcl/CmdUtil.tcl và so sánh hành vi của nó với proc_redirect trong tcl/Util.tcl, được issue nêu làm ví dụ. Kiểm tra phạm vi và cách xử lý lỗi bằng các ví dụ Tcl đã cho, bao gồm test/set_path_margin_common.tcl để xem giải pháp khắc phục hiện có. Hoàn tất khi các lệnh có thể truy cập biến của bên gọi và lỗi của chúng được chuyển đến bên gọi sau khi việc chuyển hướng đầu ra kết thúc.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Verilog
Star
658
Fork
299
Merge trung bình
1 ngày 12 giờ
Pull request đã merge (30 ngày)
28

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của The-OpenROAD-Project/OpenSTA

Tất cả issue của The-OpenROAD-Project/OpenSTA

Issue tương tự

Thêm issue về DevTools

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.