Unverified Commit effa707e authored by Madelyn Olson's avatar Madelyn Olson Committed by GitHub
Browse files

Fix incorrect error code for eval scripts and fix test error checking (#10575)

By the convention of errors, there is supposed to be a space between the code and the name.
While looking at some lua stuff I noticed that interpreter errors were not adding the space,
so some clients will try to map the detailed error message into the error.

We have tests that hit this condition, but they were just checking that the string "starts" with ERR.
I updated some other tests with similar incorrect string checking. This isn't complete though, as
there are other ways we check for ERR I didn't fix.

Produces some fun output like:
```
# Errorstats
errorstat_ERR:count=1
errorstat_ERRuser_script_1_:count=1
```
parent 95050f26
...@@ -242,7 +242,7 @@ void scriptingInit(int setup) { ...@@ -242,7 +242,7 @@ void scriptingInit(int setup) {
" i = dbg.getinfo(3,'nSl')\n" " i = dbg.getinfo(3,'nSl')\n"
" end\n" " end\n"
" if type(err) ~= 'table' then\n" " if type(err) ~= 'table' then\n"
" err = {err='ERR' .. tostring(err)}" " err = {err='ERR ' .. tostring(err)}"
" end" " end"
" if i then\n" " if i then\n"
" err['source'] = i.source\n" " err['source'] = i.source\n"
......
...@@ -479,7 +479,7 @@ int luaEngineInitEngine() { ...@@ -479,7 +479,7 @@ int luaEngineInitEngine() {
" i = dbg.getinfo(3,'nSl')\n" " i = dbg.getinfo(3,'nSl')\n"
" end\n" " end\n"
" if type(err) ~= 'table' then\n" " if type(err) ~= 'table' then\n"
" err = {err='ERR' .. tostring(err)}" " err = {err='ERR ' .. tostring(err)}"
" end" " end"
" if i then\n" " if i then\n"
" err['source'] = i.source\n" " err['source'] = i.source\n"
......
...@@ -173,7 +173,7 @@ start_server {tags {"acl external:skip"}} { ...@@ -173,7 +173,7 @@ start_server {tags {"acl external:skip"}} {
assert_equal PONG [$r2 PING] assert_equal PONG [$r2 PING]
assert_equal {} [$r2 get readwrite_str] assert_equal {} [$r2 get readwrite_str]
assert_error {ERR* not an integer *} {$r2 set readwrite_str bar ex get} assert_error {ERR * not an integer *} {$r2 set readwrite_str bar ex get}
assert_equal {OK} [$r2 set readwrite_str bar] assert_equal {OK} [$r2 set readwrite_str bar]
assert_equal {bar} [$r2 get readwrite_str] assert_equal {bar} [$r2 get readwrite_str]
......
...@@ -2,7 +2,7 @@ start_server {tags {"auth external:skip"}} { ...@@ -2,7 +2,7 @@ start_server {tags {"auth external:skip"}} {
test {AUTH fails if there is no password configured server side} { test {AUTH fails if there is no password configured server side} {
catch {r auth foo} err catch {r auth foo} err
set _ $err set _ $err
} {ERR*any password*} } {ERR *any password*}
test {Arity check for auth command} { test {Arity check for auth command} {
catch {r auth a b c} err catch {r auth a b c} err
......
...@@ -133,12 +133,12 @@ start_server {tags {"bitops"}} { ...@@ -133,12 +133,12 @@ start_server {tags {"bitops"}} {
test {BITCOUNT syntax error #1} { test {BITCOUNT syntax error #1} {
catch {r bitcount s 0} e catch {r bitcount s 0} e
set e set e
} {ERR*syntax*} } {ERR *syntax*}
test {BITCOUNT syntax error #2} { test {BITCOUNT syntax error #2} {
catch {r bitcount s 0 1 hello} e catch {r bitcount s 0 1 hello} e
set e set e
} {ERR*syntax*} } {ERR *syntax*}
test {BITCOUNT regression test for github issue #582} { test {BITCOUNT regression test for github issue #582} {
r del foo r del foo
......
...@@ -193,14 +193,14 @@ start_server {tags {"geo"}} { ...@@ -193,14 +193,14 @@ start_server {tags {"geo"}} {
r geoadd nyc xx nx -73.9454966 40.747533 "lic market" r geoadd nyc xx nx -73.9454966 40.747533 "lic market"
} err } err
set err set err
} {ERR*syntax*} } {ERR *syntax*}
test {GEOADD update with invalid option} { test {GEOADD update with invalid option} {
catch { catch {
r geoadd nyc ch xx foo -73.9454966 40.747533 "lic market" r geoadd nyc ch xx foo -73.9454966 40.747533 "lic market"
} err } err
set err set err
} {ERR*syntax*} } {ERR *syntax*}
test {GEOADD invalid coordinates} { test {GEOADD invalid coordinates} {
catch { catch {
...@@ -229,27 +229,27 @@ start_server {tags {"geo"}} { ...@@ -229,27 +229,27 @@ start_server {tags {"geo"}} {
test {GEOSEARCH FROMLONLAT and FROMMEMBER cannot exist at the same time} { test {GEOSEARCH FROMLONLAT and FROMMEMBER cannot exist at the same time} {
catch {r geosearch nyc fromlonlat -73.9798091 40.7598464 frommember xxx bybox 6 6 km asc} e catch {r geosearch nyc fromlonlat -73.9798091 40.7598464 frommember xxx bybox 6 6 km asc} e
set e set e
} {ERR*syntax*} } {ERR *syntax*}
test {GEOSEARCH FROMLONLAT and FROMMEMBER one must exist} { test {GEOSEARCH FROMLONLAT and FROMMEMBER one must exist} {
catch {r geosearch nyc bybox 3 3 km asc desc withhash withdist withcoord} e catch {r geosearch nyc bybox 3 3 km asc desc withhash withdist withcoord} e
set e set e
} {ERR*exactly one of FROMMEMBER or FROMLONLAT*} } {ERR *exactly one of FROMMEMBER or FROMLONLAT*}
test {GEOSEARCH BYRADIUS and BYBOX cannot exist at the same time} { test {GEOSEARCH BYRADIUS and BYBOX cannot exist at the same time} {
catch {r geosearch nyc fromlonlat -73.9798091 40.7598464 byradius 3 km bybox 3 3 km asc} e catch {r geosearch nyc fromlonlat -73.9798091 40.7598464 byradius 3 km bybox 3 3 km asc} e
set e set e
} {ERR*syntax*} } {ERR *syntax*}
test {GEOSEARCH BYRADIUS and BYBOX one must exist} { test {GEOSEARCH BYRADIUS and BYBOX one must exist} {
catch {r geosearch nyc fromlonlat -73.9798091 40.7598464 asc desc withhash withdist withcoord} e catch {r geosearch nyc fromlonlat -73.9798091 40.7598464 asc desc withhash withdist withcoord} e
set e set e
} {ERR*exactly one of BYRADIUS and BYBOX*} } {ERR *exactly one of BYRADIUS and BYBOX*}
test {GEOSEARCH with STOREDIST option} { test {GEOSEARCH with STOREDIST option} {
catch {r geosearch nyc fromlonlat -73.9798091 40.7598464 bybox 6 6 km asc storedist} e catch {r geosearch nyc fromlonlat -73.9798091 40.7598464 bybox 6 6 km asc storedist} e
set e set e
} {ERR*syntax*} } {ERR *syntax*}
test {GEORADIUS withdist (sorted)} { test {GEORADIUS withdist (sorted)} {
r georadius nyc -73.9798091 40.7598464 3 km withdist asc r georadius nyc -73.9798091 40.7598464 3 km withdist asc
...@@ -274,12 +274,12 @@ start_server {tags {"geo"}} { ...@@ -274,12 +274,12 @@ start_server {tags {"geo"}} {
test {GEORADIUS with ANY but no COUNT} { test {GEORADIUS with ANY but no COUNT} {
catch {r georadius nyc -73.9798091 40.7598464 10 km ANY ASC} e catch {r georadius nyc -73.9798091 40.7598464 10 km ANY ASC} e
set e set e
} {ERR*ANY*requires*COUNT*} } {ERR *ANY*requires*COUNT*}
test {GEORADIUS with COUNT but missing integer argument} { test {GEORADIUS with COUNT but missing integer argument} {
catch {r georadius nyc -73.9798091 40.7598464 10 km COUNT} e catch {r georadius nyc -73.9798091 40.7598464 10 km COUNT} e
set e set e
} {ERR*syntax*} } {ERR *syntax*}
test {GEORADIUS with COUNT DESC} { test {GEORADIUS with COUNT DESC} {
r georadius nyc -73.9798091 40.7598464 10 km COUNT 2 DESC r georadius nyc -73.9798091 40.7598464 10 km COUNT 2 DESC
......
...@@ -23,9 +23,9 @@ start_server {tags {"introspection"}} { ...@@ -23,9 +23,9 @@ start_server {tags {"introspection"}} {
assert_error "ERR wrong number of arguments for 'client|kill' command" {r client kill} assert_error "ERR wrong number of arguments for 'client|kill' command" {r client kill}
assert_error "ERR syntax error*" {r client kill id 10 wrong_arg} assert_error "ERR syntax error*" {r client kill id 10 wrong_arg}
assert_error "ERR*greater than 0*" {r client kill id str} assert_error "ERR *greater than 0*" {r client kill id str}
assert_error "ERR*greater than 0*" {r client kill id -1} assert_error "ERR *greater than 0*" {r client kill id -1}
assert_error "ERR*greater than 0*" {r client kill id 0} assert_error "ERR *greater than 0*" {r client kill id 0}
assert_error "ERR Unknown client type*" {r client kill type wrong_type} assert_error "ERR Unknown client type*" {r client kill type wrong_type}
...@@ -409,11 +409,11 @@ start_server {tags {"introspection"}} { ...@@ -409,11 +409,11 @@ start_server {tags {"introspection"}} {
} }
test {CONFIG SET duplicate configs} { test {CONFIG SET duplicate configs} {
assert_error "ERR*duplicate*" {r config set maxmemory 10000001 maxmemory 10000002} assert_error "ERR *duplicate*" {r config set maxmemory 10000001 maxmemory 10000002}
} }
test {CONFIG SET set immutable} { test {CONFIG SET set immutable} {
assert_error "ERR*immutable*" {r config set daemonize yes} assert_error "ERR *immutable*" {r config set daemonize yes}
} }
test {CONFIG GET hidden configs} { test {CONFIG GET hidden configs} {
...@@ -448,8 +448,8 @@ start_server {tags {"introspection"}} { ...@@ -448,8 +448,8 @@ start_server {tags {"introspection"}} {
start_server {tags {"introspection external:skip"} overrides {enable-protected-configs {no} enable-debug-command {no}}} { start_server {tags {"introspection external:skip"} overrides {enable-protected-configs {no} enable-debug-command {no}}} {
test {cannot modify protected configuration - no} { test {cannot modify protected configuration - no} {
assert_error "ERR*protected*" {r config set dir somedir} assert_error "ERR *protected*" {r config set dir somedir}
assert_error "ERR*DEBUG command not allowed*" {r DEBUG HELP} assert_error "ERR *DEBUG command not allowed*" {r DEBUG HELP}
} {} {needs:debug} } {} {needs:debug}
} }
...@@ -464,8 +464,8 @@ start_server {config "minimal.conf" tags {"introspection external:skip"} overrid ...@@ -464,8 +464,8 @@ start_server {config "minimal.conf" tags {"introspection external:skip"} overrid
if {$myaddr != "" && ![string match {127.*} $myaddr]} { if {$myaddr != "" && ![string match {127.*} $myaddr]} {
# Non-loopback client should fail # Non-loopback client should fail
set r2 [get_nonloopback_client] set r2 [get_nonloopback_client]
assert_error "ERR*protected*" {$r2 config set dir somedir} assert_error "ERR *protected*" {$r2 config set dir somedir}
assert_error "ERR*DEBUG command not allowed*" {$r2 DEBUG HELP} assert_error "ERR *DEBUG command not allowed*" {$r2 DEBUG HELP}
} }
} {} {needs:debug} } {} {needs:debug}
} }
......
...@@ -36,6 +36,6 @@ start_server {tags {"modules"}} { ...@@ -36,6 +36,6 @@ start_server {tags {"modules"}} {
start_server {tags {"modules external:skip"} overrides {enable-module-command no}} { start_server {tags {"modules external:skip"} overrides {enable-module-command no}} {
test {module command disabled} { test {module command disabled} {
assert_error "ERR*MODULE command not allowed*" {r module load $testmodule} assert_error "ERR *MODULE command not allowed*" {r module load $testmodule}
} }
} }
\ No newline at end of file
...@@ -447,12 +447,12 @@ start_server {tags {"scripting"}} { ...@@ -447,12 +447,12 @@ start_server {tags {"scripting"}} {
test {Globals protection reading an undeclared global variable} { test {Globals protection reading an undeclared global variable} {
catch {run_script {return a} 0} e catch {run_script {return a} 0} e
set e set e
} {ERR*attempted to access * global*} } {ERR *attempted to access * global*}
test {Globals protection setting an undeclared global*} { test {Globals protection setting an undeclared global*} {
catch {run_script {a=10} 0} e catch {run_script {a=10} 0} e
set e set e
} {ERR*attempted to create global*} } {ERR *attempted to create global*}
test {Test an example script DECR_IF_GT} { test {Test an example script DECR_IF_GT} {
set decr_if_gt { set decr_if_gt {
......
...@@ -507,8 +507,8 @@ start_server {tags {"hash"}} { ...@@ -507,8 +507,8 @@ start_server {tags {"hash"}} {
catch {r hincrby smallhash str 1} smallerr catch {r hincrby smallhash str 1} smallerr
catch {r hincrby bighash str 1} bigerr catch {r hincrby bighash str 1} bigerr
set rv {} set rv {}
lappend rv [string match "ERR*not an integer*" $smallerr] lappend rv [string match "ERR *not an integer*" $smallerr]
lappend rv [string match "ERR*not an integer*" $bigerr] lappend rv [string match "ERR *not an integer*" $bigerr]
} {1 1} } {1 1}
test {HINCRBY fails against hash value with spaces (right)} { test {HINCRBY fails against hash value with spaces (right)} {
...@@ -517,8 +517,8 @@ start_server {tags {"hash"}} { ...@@ -517,8 +517,8 @@ start_server {tags {"hash"}} {
catch {r hincrby smallhash str 1} smallerr catch {r hincrby smallhash str 1} smallerr
catch {r hincrby bighash str 1} bigerr catch {r hincrby bighash str 1} bigerr
set rv {} set rv {}
lappend rv [string match "ERR*not an integer*" $smallerr] lappend rv [string match "ERR *not an integer*" $smallerr]
lappend rv [string match "ERR*not an integer*" $bigerr] lappend rv [string match "ERR *not an integer*" $bigerr]
} {1 1} } {1 1}
test {HINCRBY can detect overflows} { test {HINCRBY can detect overflows} {
...@@ -579,8 +579,8 @@ start_server {tags {"hash"}} { ...@@ -579,8 +579,8 @@ start_server {tags {"hash"}} {
catch {r hincrbyfloat smallhash str 1} smallerr catch {r hincrbyfloat smallhash str 1} smallerr
catch {r hincrbyfloat bighash str 1} bigerr catch {r hincrbyfloat bighash str 1} bigerr
set rv {} set rv {}
lappend rv [string match "ERR*not*float*" $smallerr] lappend rv [string match "ERR *not*float*" $smallerr]
lappend rv [string match "ERR*not*float*" $bigerr] lappend rv [string match "ERR *not*float*" $bigerr]
} {1 1} } {1 1}
test {HINCRBYFLOAT fails against hash value with spaces (right)} { test {HINCRBYFLOAT fails against hash value with spaces (right)} {
...@@ -589,15 +589,15 @@ start_server {tags {"hash"}} { ...@@ -589,15 +589,15 @@ start_server {tags {"hash"}} {
catch {r hincrbyfloat smallhash str 1} smallerr catch {r hincrbyfloat smallhash str 1} smallerr
catch {r hincrbyfloat bighash str 1} bigerr catch {r hincrbyfloat bighash str 1} bigerr
set rv {} set rv {}
lappend rv [string match "ERR*not*float*" $smallerr] lappend rv [string match "ERR *not*float*" $smallerr]
lappend rv [string match "ERR*not*float*" $bigerr] lappend rv [string match "ERR *not*float*" $bigerr]
} {1 1} } {1 1}
test {HINCRBYFLOAT fails against hash value that contains a null-terminator in the middle} { test {HINCRBYFLOAT fails against hash value that contains a null-terminator in the middle} {
r hset h f "1\x002" r hset h f "1\x002"
catch {r hincrbyfloat h f 1} err catch {r hincrbyfloat h f 1} err
set rv {} set rv {}
lappend rv [string match "ERR*not*float*" $err] lappend rv [string match "ERR *not*float*" $err]
} {1} } {1}
test {HSTRLEN against the small hash} { test {HSTRLEN against the small hash} {
......
...@@ -111,21 +111,21 @@ start_server {tags {"incr"}} { ...@@ -111,21 +111,21 @@ start_server {tags {"incr"}} {
r set novar " 11" r set novar " 11"
catch {r incrbyfloat novar 1.0} err catch {r incrbyfloat novar 1.0} err
format $err format $err
} {ERR*valid*} } {ERR *valid*}
test {INCRBYFLOAT fails against key with spaces (right)} { test {INCRBYFLOAT fails against key with spaces (right)} {
set err {} set err {}
r set novar "11 " r set novar "11 "
catch {r incrbyfloat novar 1.0} err catch {r incrbyfloat novar 1.0} err
format $err format $err
} {ERR*valid*} } {ERR *valid*}
test {INCRBYFLOAT fails against key with spaces (both)} { test {INCRBYFLOAT fails against key with spaces (both)} {
set err {} set err {}
r set novar " 11 " r set novar " 11 "
catch {r incrbyfloat novar 1.0} err catch {r incrbyfloat novar 1.0} err
format $err format $err
} {ERR*valid*} } {ERR *valid*}
test {INCRBYFLOAT fails against a key holding a list} { test {INCRBYFLOAT fails against a key holding a list} {
r del mylist r del mylist
...@@ -146,7 +146,7 @@ start_server {tags {"incr"}} { ...@@ -146,7 +146,7 @@ start_server {tags {"incr"}} {
# p.s. no way I can force NaN to test it from the API because # p.s. no way I can force NaN to test it from the API because
# there is no way to increment / decrement by infinity nor to # there is no way to increment / decrement by infinity nor to
# perform divisions. # perform divisions.
} {ERR*would produce*} } {ERR *would produce*}
} }
test {INCRBYFLOAT decrement} { test {INCRBYFLOAT decrement} {
...@@ -159,7 +159,7 @@ start_server {tags {"incr"}} { ...@@ -159,7 +159,7 @@ start_server {tags {"incr"}} {
r setrange foo 2 2 r setrange foo 2 2
catch {r incrbyfloat foo 1} err catch {r incrbyfloat foo 1} err
format $err format $err
} {ERR*valid*} } {ERR *valid*}
test {No negative zero} { test {No negative zero} {
r del foo r del foo
......
...@@ -1173,7 +1173,7 @@ foreach {pop} {BLPOP BLMPOP_LEFT} { ...@@ -1173,7 +1173,7 @@ foreach {pop} {BLPOP BLMPOP_LEFT} {
test "$pop: with negative timeout" { test "$pop: with negative timeout" {
set rd [redis_deferring_client] set rd [redis_deferring_client]
bpop_command $rd $pop blist1 -1 bpop_command $rd $pop blist1 -1
assert_error "ERR*is negative*" {$rd read} assert_error "ERR *is negative*" {$rd read}
$rd close $rd close
} }
......
...@@ -770,7 +770,7 @@ start_server {tags {"stream xsetid"}} { ...@@ -770,7 +770,7 @@ start_server {tags {"stream xsetid"}} {
catch {r XSETID mystream "1-1"} err catch {r XSETID mystream "1-1"} err
r XADD mystream MAXLEN 0 * a b r XADD mystream MAXLEN 0 * a b
set err set err
} {ERR*smaller*} } {ERR *smaller*}
test {XSETID cannot SETID on non-existent key} { test {XSETID cannot SETID on non-existent key} {
catch {r XSETID stream 1-1} err catch {r XSETID stream 1-1} err
...@@ -790,7 +790,7 @@ start_server {tags {"stream xsetid"}} { ...@@ -790,7 +790,7 @@ start_server {tags {"stream xsetid"}} {
test {XSETID errors on negstive offset} { test {XSETID errors on negstive offset} {
catch {r XSETID stream 1-1 ENTRIESADDED -1 MAXDELETEDID 0-0} err catch {r XSETID stream 1-1 ENTRIESADDED -1 MAXDELETEDID 0-0} err
set _ $err set _ $err
} {ERR*must be positive} } {ERR *must be positive}
test {XSETID cannot set the maximal tombstone with larger ID} { test {XSETID cannot set the maximal tombstone with larger ID} {
r DEL x r DEL x
...@@ -799,7 +799,7 @@ start_server {tags {"stream xsetid"}} { ...@@ -799,7 +799,7 @@ start_server {tags {"stream xsetid"}} {
catch {r XSETID x "1-0" ENTRIESADDED 1 MAXDELETEDID "2-0" } err catch {r XSETID x "1-0" ENTRIESADDED 1 MAXDELETEDID "2-0" } err
r XADD mystream MAXLEN 0 * a b r XADD mystream MAXLEN 0 * a b
set err set err
} {ERR*smaller*} } {ERR *smaller*}
test {XSETID cannot set the offset to less than the length} { test {XSETID cannot set the offset to less than the length} {
r DEL x r DEL x
...@@ -808,7 +808,7 @@ start_server {tags {"stream xsetid"}} { ...@@ -808,7 +808,7 @@ start_server {tags {"stream xsetid"}} {
catch {r XSETID x "1-0" ENTRIESADDED 0 MAXDELETEDID "0-0" } err catch {r XSETID x "1-0" ENTRIESADDED 0 MAXDELETEDID "0-0" } err
r XADD mystream MAXLEN 0 * a b r XADD mystream MAXLEN 0 * a b
set err set err
} {ERR*smaller*} } {ERR *smaller*}
} }
start_server {tags {"stream offset"}} { start_server {tags {"stream offset"}} {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment