Any idea if this is a bug or just undocumented behavior? It's just me expecting the wrong thing.
Script demonstrating the problem:
Code: Select all
:put "#### Starting :onerror Tests ####\n"
:put "## Test 2: Error in scope with and before no error"
{
:put "# Test 2 part 1: erroring :onerror"
:put "before :onerror \$ErrVar: $ErrVar"
:onerror ErrVar in={
:put "inside :onerror in={} \$ErrVar: $ErrVar"
:error "error msg 2p1"
} do={
put "inside :onerror do={} \$ErrVar: $ErrVar"
}
:put "Post :onerror in scope \$ErrVar: $ErrVar"
:put "\n# Test 2 part 2: not erroring :onerror"
:put "before :onerror \$ErrVar: $ErrVar"
:onerror ErrVar in={
:put "inside :onerror in={} \$ErrVar: $ErrVar"
#:put "msg 2p2"
} do={
put "inside :onerror do={} \$ErrVar: $ErrVar"
}
:put "Post :onerror in scope \$ErrVar: $ErrVar"
}
:put "\n### This demonstrates that \$ErrVar used in the :onerror is not scoped to the in={} and do={} of the :onerror."
:put "### This is not the behavior that I would expect, and isn't documented."
:put "\n#### Ended :onerror Tests ####"
Code: Select all
#### Starting :onerror Tests ####
## Test 2: Error in scope with and before no error
# Test 2 part 1: erroring :onerror
before :onerror $ErrVar:
inside :onerror in={} $ErrVar:
inside :onerror do={} $ErrVar: error msg 2p1
Post :onerror in scope $ErrVar: error msg 2p1
# Test 2 part 2: not erroring :onerror
before :onerror $ErrVar: error msg 2p1
inside :onerror in={} $ErrVar: error msg 2p1
inside :onerror do={} $ErrVar: conditional not boolean
Post :onerror in scope $ErrVar: conditional not boolean
### This demonstrates that $ErrVar used in the :onerror is not scoped to the in={} and do={} of the :onerror.
### This is not the behavior that I would expect, and isn't documented.
#### Ended :onerror Tests ####
Script file loaded and executed successfully
Script snippet of where this bug occurs (these are some sloppy test for a log/print output function I wrote):
Code: Select all
#########
# Tests #
#########
### For ErrOutFn ###
:put "\n#### Tests for ErrOutFn ####";
:global DEBUG true;
:put "## Input validation that should pass"
:foreach Fn in={$ErrOutFn} do={
:put "";
:put "### LOOP ITERATION";
:put "";
:put "## Input Validation Tests";
:put "# Tests that should pass";
:put "\$ErrVal: $ErrVal"
{
:onerror ErrVal in={
$Fn "warning" "SomeFn" "should not error";
} do={
:put "Should not show error: $ErrVal";
:put "";
}
}
:put "\$ErrVal: $ErrVal"
:put "";
:put "# Tests that should fail";
{
:onerror ErrVal in={
$Fn ;
} do={
:put "Should show error (I provided no input): $ErrVal";
:put "";
}
}
:put "\$ErrVal: $ErrVal"
{
:onerror ErrVal in={
$Fn "info";
} do={
:put "Should show error (I provided only \$1): $ErrVal";
:put "";
}
}
:put "\$ErrVal: $ErrVal"
{
:onerror ErrVal in={
$Fn "info" "SomeFn";
} do={
:put "Should show error (I provided only \$1,\$2): $ErrVal";
:put "";
}
}
:put "\$ErrVal: $ErrVal"
{
:onerror ErrVal in={
$Fn "info" "SomeFn" "test 1" true;
} do={
:put "Should show error: $ErrVal";
:put "";
}
}
:put "\$ErrVal: $ErrVal"
{
:onerror ErrVal in={
$Fn "warning" "SomeFn" "test 2" 1;
} do={
:put "Should show error: $ErrVal";
:put "";
}
}
:put "\$ErrVal: $ErrVal"
{
:onerror ErrVal in={
$Fn "debug" "SomeFn" "test 3" "1";
} do={
:put "Should show error: $ErrVal";
:put "";
}
}
:put "\$ErrVal: $ErrVal"
{
:onerror ErrVal in={
$Fn "warning" "SomeFn" "test 4, default exit (do exit)"
} do={
:put "Should show error: $ErrVal";
:put "";
}
}
:put "\$ErrVal: $ErrVal"
$Fn "error" "SomeFn" "test 5, should not exit" "false";
{
:onerror ErrVal in={
$Fn "info" "SomeFn" "test 6, default exit (do exit)";
} do={
:put "Should show error: $ErrVal";
:put "";
}
}
:put "\$ErrVal: $ErrVal"
{
:onerror ErrVal in={
$Fn "debug" "SomeFn" "test 7, default exit (do exit)";
} do={
:put "Should show error: $ErrVal";
:put "";
}
}
:put "\$ErrVal: $ErrVal"
}
:put "\$Fn: $Fn"
# I need to declare and reset $ErrVar otherwise I get a "condition is not boolean error:, probably a bug
#:local ErrVal;
#:set ErrVal;
### For DbgFn ###
:put "\n#### Tests for DbgFn ####";
:foreach Fn in={$DbgFn} do={
:put "";
:put "### LOOP ITERATION";
:put "";
:put "## Input Validation Tests";
:put "\$ErrVal: $ErrVal"
{
:onerror ErrVal in={
$Fn ;
} do={
:put "Should show error (I provided no input): $ErrVal";
:put "";
}
}
:put "\$ErrVal: $ErrVal"
{
:onerror ErrVal in={
$Fn "SomeFn";
} do={
:put "Should show error (I provided only \$1): $ErrVal";
:put "";
}
}
# :local ErrVal;
# :set ErrVal;
:put "\$ErrVal: $ErrVal";
:put "\$ErrVal data type: $[:typeof "$ErrVal"]";
}
:set DEBUG;
Code: Select all
#### Tests for ErrOutFn ####
## Input validation that should pass
### LOOP ITERATION
## Input Validation Tests
# Tests that should pass
$ErrVal:
**Dbg: warning,SomeFn: should not error
Should not show error: warning,SomeFn: should not error
$ErrVal:
# Tests that should fail
warning: $OutBaseFn: previous log message had improperly specified severity $1 to this function should be: debug, info, warning, or error
**Dbg: invalid,:
Should show error (I provided no input): invalid,:
$ErrVal:
**Dbg: info,:
Should show error (I provided only $1): info,:
$ErrVal:
**Dbg: info,SomeFn:
Should show error (I provided only $1,$2): info,SomeFn:
$ErrVal:
**Dbg: info,SomeFn: test 1
Should show error: info,SomeFn: test 1
$ErrVal:
**Dbg: warning,SomeFn: test 2
Should show error: warning,SomeFn: test 2
$ErrVal:
**Dbg: debug,SomeFn: test 3
Should show error: debug,SomeFn: test 3
$ErrVal:
**Dbg: warning,SomeFn: test 4, default exit (do exit)
Should show error: warning,SomeFn: test 4, default exit (do exit)
$ErrVal:
**Dbg: error,SomeFn: test 5, should not exit
**Dbg: info,SomeFn: test 6, default exit (do exit)
Should show error: info,SomeFn: test 6, default exit (do exit)
$ErrVal:
**Dbg: debug,SomeFn: test 7, default exit (do exit)
Should show error: debug,SomeFn: test 7, default exit (do exit)
$ErrVal:
$Fn:
#### Tests for DbgFn ####
### LOOP ITERATION
## Input Validation Tests
$ErrVal:
**Dbg: debug,:
Should show error (I provided no input): conditional not boolean
$ErrVal:
**Dbg: debug,SomeFn:
Should show error (I provided only $1): conditional not boolean
$ErrVal:
$ErrVal data type: nothing
Script file loaded and executed successfully