Technical Forum
Ask questions. Discover Answers.
Showing results for 
Search instead for 
Did you mean: 
Custom Alert Banner

Returning a configuration object changes its type



I'm building a cli script to automate some of the configuration tasks I have to do. I've encountered some strange behaviour, which I don't understand.

So this example prints me the description of the sys ntp configuration object.

set ntp [lindex [tmsh::get_config /sys ntp] 0]
puts "[tmsh::get_field_value $ntp description]"

As you probably know tmsh::get_config always returns a collection. I sometimes only want to get a single item (and make sure that it really is only a single item). That's why I thought it would be great to have a procedure that does that check every time:

proc get_single_config {args} {
    set items [tmsh::get_config $args]
    if {[llength $items] eq 1} {
        return [lindex $items 0]
    } else {
        error "list $args yielded [llength $items] results"

Then I run:

set ntp [get_single_config /sys ntp]
puts "[tmsh::get_field_value $ntp description]"

And I get the following error:

test: script failed to complete:
can't eval proc: "script::run"
unexpected TCL object type
    while executing
"tmsh::get_field_value $ntp description"
    (procedure "script::run" line 4)
    invoked from within
"script::run" line:1
script did not successfully complete, status:1

When I add a get_field_value just before the return on get_single_config it works. But after it is returned from the procedure, it seems like the object type changes. Since I'm somewhat new to TCL it might just be I'm using TCL wrong. It's not like I can't work around this, but I'm curious to know what is causing this.