Skip to content
Snippets Groups Projects
Commit 3e87c1bf authored by Iustin Pop's avatar Iustin Pop
Browse files

Enhance the error reporting


Since daemon startup error will be often related to socket errors, so it
makes sense to change the original reporting:

  Error when starting daemon process: "(98, 'Address already in use')"

Into:

  Error when starting daemon process: 'Socket-related error: Address
  already in use (errno=98)'

Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 3ee53f1f
No related branches found
No related tags found
No related merge requests found
...@@ -491,8 +491,8 @@ class Mainloop(object): ...@@ -491,8 +491,8 @@ class Mainloop(object):
def _VerifyDaemonUser(daemon_name): def _VerifyDaemonUser(daemon_name):
"""Verifies the process uid matches the configured uid. """Verifies the process uid matches the configured uid.
This method verifies that a daemon is started as the user it is intended to be This method verifies that a daemon is started as the user it is
run intended to be run
@param daemon_name: The name of daemon to be started @param daemon_name: The name of daemon to be started
@return: A tuple with the first item indicating success or not, @return: A tuple with the first item indicating success or not,
...@@ -512,6 +512,33 @@ def _VerifyDaemonUser(daemon_name): ...@@ -512,6 +512,33 @@ def _VerifyDaemonUser(daemon_name):
daemon_uids[daemon_name]) daemon_uids[daemon_name])
def _BeautifyError(err):
"""Try to format an error better.
Since we're dealing with daemon startup errors, in many cases this
will be due to socket error and such, so we try to format these cases better.
@param err: an exception object
@rtype: string
@return: the formatted error description
"""
try:
if isinstance(err, socket.error):
return "Socket-related error: %s (errno=%s)" % (err.args[1], err.args[0])
elif isinstance(err, EnvironmentError):
if err.filename is None:
return "%s (errno=%s)" % (err.strerror, err.errno)
else:
return "%s (file %s) (errno=%s)" % (err.strerror, err.filename,
err.errno)
else:
return str(err)
except Exception: # pylint: disable-msg=W0703
logging.exception("Error while handling existing error %s", err)
return "%s" % str(err)
def GenericMain(daemon_name, optionparser, def GenericMain(daemon_name, optionparser,
check_fn, prepare_fn, exec_fn, check_fn, prepare_fn, exec_fn,
multithreaded=False, console_logging=False, multithreaded=False, console_logging=False,
...@@ -645,7 +672,7 @@ def GenericMain(daemon_name, optionparser, ...@@ -645,7 +672,7 @@ def GenericMain(daemon_name, optionparser,
logging.info("%s daemon startup", daemon_name) logging.info("%s daemon startup", daemon_name)
except Exception, err: except Exception, err:
if wpipe is not None: if wpipe is not None:
os.write(wpipe, str(err)) os.write(wpipe, _BeautifyError(err))
raise raise
if wpipe is not None: if wpipe is not None:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment