1
0
mirror of https://github.com/JoelBender/bacpypes synced 2025-09-28 22:15:23 +08:00

trap the invalid array index

This commit is contained in:
Joel Bender 2016-11-14 00:18:30 -05:00
parent ba31af7849
commit 2f8f147517
3 changed files with 27 additions and 9 deletions

View File

@ -174,8 +174,11 @@ class Property(Logging):
raise ExecutionError(errorClass='property', errorCode='propertyIsNotAnArray')
if value is not None:
# dive in, the water's fine
value = value[arrayIndex]
try:
# dive in, the water's fine
value = value[arrayIndex]
except IndexError:
raise ExecutionError(errorClass='property', errorCode='invalidArrayIndex')
# all set
return value
@ -228,7 +231,10 @@ class Property(Logging):
# seems to be OK, let the array object take over
if _debug: Property._debug(" - forwarding to array")
arry[arrayIndex] = value
try:
arry[arrayIndex] = value
except IndexError:
raise ExecutionError(errorClass='property', errorCode='invalidArrayIndex')
# check for monitors, call each one with the old and new value
if is_monitored:

View File

@ -175,8 +175,11 @@ class Property:
raise ExecutionError(errorClass='property', errorCode='propertyIsNotAnArray')
if value is not None:
# dive in, the water's fine
value = value[arrayIndex]
try:
# dive in, the water's fine
value = value[arrayIndex]
except IndexError:
raise ExecutionError(errorClass='property', errorCode='invalidArrayIndex')
# all set
return value
@ -229,7 +232,10 @@ class Property:
# seems to be OK, let the array object take over
if _debug: Property._debug(" - forwarding to array")
arry[arrayIndex] = value
try:
arry[arrayIndex] = value
except IndexError:
raise ExecutionError(errorClass='property', errorCode='invalidArrayIndex')
# check for monitors, call each one with the old and new value
if is_monitored:

View File

@ -175,8 +175,11 @@ class Property:
raise ExecutionError(errorClass='property', errorCode='propertyIsNotAnArray')
if value is not None:
# dive in, the water's fine
value = value[arrayIndex]
try:
# dive in, the water's fine
value = value[arrayIndex]
except IndexError:
raise ExecutionError(errorClass='property', errorCode='invalidArrayIndex')
# all set
return value
@ -229,7 +232,10 @@ class Property:
# seems to be OK, let the array object take over
if _debug: Property._debug(" - forwarding to array")
arry[arrayIndex] = value
try:
arry[arrayIndex] = value
except IndexError:
raise ExecutionError(errorClass='property', errorCode='invalidArrayIndex')
# check for monitors, call each one with the old and new value
if is_monitored: