set myvar ""
global myvar
will fail
global myvar
set myvar ""
will succeed.
Depending on your desires you may wish to change "global errorCode
errorInfo" to
if {[info exists errorCode]} {
unset errorCode
}
if {[info exists errorInfo]} {
unset errorInfo
}
global errorCode errorInfo