TCL print_var support for unset variable
If var_value is not defined, catch the error and print its value as
"** variable not set **".
Change-Id: I437ce0c08dd17e92704776e58e8aaf55de4141fa
Signed-off-by: Michael Walsh <micwalsh@us.ibm.com>
diff --git a/lib/print.tcl b/lib/print.tcl
index 6458cc4..acee5ec 100755
--- a/lib/print.tcl
+++ b/lib/print.tcl
@@ -509,7 +509,19 @@
return $buffer
}
- return [sprint_varx $var_name $var_value {*}$args]
+ # If var_value is not defined, catch the error and print its value as
+ # "variable not set".
+ if {[catch {set buffer [sprint_varx $var_name $var_value {*}$args]} error_text options]} {
+ set regex ":\[ \]no\[ \]such\[ \]variable"
+ if { [regexp -expanded ${regex} ${error_text}]} {
+ return [sprint_varx $var_name {** variable not set **} {*}$args]
+ } else {
+ print_dict options
+ exit 1
+ }
+ } else {
+ return $buffer
+ }
}