simplify errors on startup

Change-Id: I2b12abf15487000992e019e12002303036766d52
This commit is contained in:
2025-11-03 14:06:19 +01:00
parent 03c2f6eb98
commit ebfb8a005d
3 changed files with 41 additions and 65 deletions

View File

@@ -420,8 +420,8 @@ class Module(HasAccessibles):
aobj.checkProperties()
except (ConfigError, ProgrammingError) as e:
self.errors.append(f'{aname}: {e}')
if self.errors:
raise ConfigError(self.errors)
# if self.errors:
# raise ConfigError(self.errors)
# helper cfg-editor
def __iter__(self):

View File

@@ -51,7 +51,7 @@ class SecNode:
self.log = logger
self.srv = srv
# set of modules that failed creation
self.failed_modules = set()
# self.failed_modules = set()
# list of errors that occured during initialization
self.errors = []
self.traceback_counter = 0
@@ -80,24 +80,22 @@ class SecNode:
# also call earlyInit on the modules
self.log.debug('initializing module %r', modulename)
try:
modobj.earlyInit()
if not modobj.earlyInitDone:
self.errors.append(f'{modobj.earlyInit.__qualname__} was not '
f'called, probably missing super call')
modobj.initModule()
if not modobj.initModuleDone:
self.errors.append(f'{modobj.initModule.__qualname__} was not '
f'called, probably missing super call')
except InitFailed:
raise
except Exception as e:
if self.traceback_counter == 0:
self.log.exception(traceback.format_exc())
self.traceback_counter += 1
self.errors.append(f'error initializing {modulename}: {e!r}')
modobj._initfailed = True
raise InitFailed('try to access erroneous module') from e
# try:
modobj.earlyInit()
if not modobj.earlyInitDone:
self.errors.append(f'{modobj.earlyInit.__qualname__} was not '
f'called, probably missing super call')
modobj.initModule()
if not modobj.initModuleDone:
self.errors.append(f'{modobj.initModule.__qualname__} was not '
f'called, probably missing super call')
# except Exception as e:
# if self.traceback_counter == 0:
# self.log.exception(traceback.format_exc())
# self.traceback_counter += 1
# self.errors.append(f'error initializing {modulename}: {e!r}')
# modobj._initfailed = True
# raise InitFailed('try to access erroneous module') from e
modobj._isinitialized = True
self.log.info('initialized module %r', modulename)
return modobj
@@ -109,11 +107,8 @@ class SecNode:
When creating a new module, srv.module_config is accessed to get the
modules configuration.
"""
modobj = self.modules.get(modulename)
if modobj:
if modobj._initfailed:
raise InitFailed('try to access erroneous module')
return modobj
if modulename in self.modules:
return self.modules[modulename]
if modulename in list(self.modules.values()):
# it's actually already the module object
return modulename
@@ -126,20 +121,20 @@ class SecNode:
raise NoSuchModuleError(f'Module {modulename!r} does not exist on '
f'this SEC-Node!')
opts = dict(opts)
pymodule = None
# pymodule = None
classname = opts.pop('cls')
try: # pylint: disable=no-else-return
classname = opts.pop('cls')
if isinstance(classname, str):
pymodule = classname.rpartition('.')[0]
if pymodule in self.failed_modules:
# creation has failed already once, do not try again
return None
# pymodule = classname.rpartition('.')[0]
# if pymodule in self.failed_modules:
# # creation has failed already once, do not try again
# return None
cls = get_class(classname)
else:
pymodule = classname.__module__
if pymodule in self.failed_modules:
# creation has failed already once, do not try again
return None
# pymodule = classname.__module__
# if pymodule in self.failed_modules:
# # creation has failed already once, do not try again
# return None
cls = classname
if not issubclass(cls, Module):
self.errors.append(f'{cls.__name__} is not a Module')
@@ -147,30 +142,14 @@ class SecNode:
except Exception as e:
if str(e) == 'no such class':
self.errors.append(f'{classname} not found')
else:
self.failed_modules.add(pymodule)
if self.traceback_counter == 0:
self.log.exception(traceback.format_exc())
self.traceback_counter += 1
self.errors.append(f'error importing {classname}')
return None
return None
raise
else:
try:
modobj = cls(modulename, self.log.parent.getChild(modulename),
opts, self.srv)
except ConfigError as e:
self.errors.append(f'error creating module {modulename}:')
for errtxt in e.args[0] if isinstance(e.args[0], list) else [e.args[0]]:
self.errors.append(' ' + errtxt)
modobj = None
except Exception as e:
if self.traceback_counter == 0:
self.log.exception(traceback.format_exc())
self.traceback_counter += 1
self.errors.append(f'error creating {modulename}')
modobj = None
if modobj:
self.add_module(modobj, modulename)
modobj = cls(modulename, self.log.parent.getChild(modulename),
opts, self.srv)
for errtxt in modobj.errors:
self.errors.append(' ' + errtxt)
self.add_module(modobj, modulename)
return modobj
def create_modules(self):
@@ -220,11 +199,8 @@ class SecNode:
modules = {}
result = {'modules': modules}
for modulename in list(self.modules):
try:
modobj = self.get_module(modulename)
except InitFailed:
continue
if not modobj.export:
modobj = self.get_module(modulename)
if not modobj or not modobj.export:
continue
# some of these need rework !
mod_desc = {'accessibles': self.export_accessibles(modobj)}

View File

@@ -308,7 +308,7 @@ class Server:
# all errors from initialization process
errors = self.secnode.errors
if not self._testonly and not errors: # do not start pollers when we have errors already
if not self._testonly: # do not start pollers when we have errors already
start_events = MultiEvent(default_timeout=30)
for modname, modobj in self.secnode.modules.items():
# startModule must return either a timeout value or None (default 30 sec)