feat: return propertyerror in function

This commit is contained in:
egarette@silique.fr 2024-10-25 22:15:45 +02:00
parent 54ac0c980a
commit b5d477a439
3 changed files with 19 additions and 2 deletions

View file

@ -16,7 +16,7 @@
"""
from .function import calc_value, calc_value_property_help, valid_ip_netmask, \
valid_network_netmask, valid_in_network, valid_broadcast, \
valid_not_equal, function_waiting_for_dict
valid_not_equal, function_waiting_for_dict, function_waiting_for_error
from .autolib import Calculation, Params, ParamOption, ParamDynOption, ParamSelfOption, \
ParamValue, ParamIndex, ParamIdentifier, ParamInformation, ParamSelfInformation
from .option import *
@ -51,6 +51,7 @@ allfuncs = ['Calculation',
'valid_in_network',
'valid_broadcast',
'function_waiting_for_dict',
'function_waiting_for_error',
]
allfuncs.extend(all_options)
del(all_options)

View file

@ -25,7 +25,7 @@ import weakref
from .error import PropertiesOptionError, ConfigError, LeadershipError, ValueWarning
from .i18n import _
from .setting import undefined, ConfigBag
from .function import FUNCTION_WAITING_FOR_DICT
from .function import FUNCTION_WAITING_FOR_DICT, FUNCTION_WAITING_FOR_ERROR
# ____________________________________________________________
@ -662,6 +662,11 @@ def carry_out_calculation(subconfig: 'SubConfig',
args.append({'propertyerror': str(err), 'name': option.impl_get_display_name(subconfig)})
else:
kwargs[key] = {'propertyerror': str(err), 'name': option.impl_get_display_name(subconfig)}
if callback.__name__ in FUNCTION_WAITING_FOR_ERROR:
if key is None:
args.append(err)
else:
kwargs[key] = err
ret = calculate(subconfig,
callback,
allow_value_error,

View file

@ -23,6 +23,7 @@ from .error import display_list
FUNCTION_WAITING_FOR_DICT = []
FUNCTION_WAITING_FOR_ERROR = []
def function_waiting_for_dict(function):
@ -36,6 +37,16 @@ def function_waiting_for_dict(function):
return function
def function_waiting_for_error(function):
"""functions (calculation or validation) receive by default only the value of other options
set PropertyError too
"""
name = function.__name__
if name not in FUNCTION_WAITING_FOR_ERROR:
FUNCTION_WAITING_FOR_ERROR.append(name)
return function
@function_waiting_for_dict
def valid_network_netmask(network: dict,
netmask: dict,