'Handle an error in a callback.
Args:
callback (dict): the callback representation.
trace (list): the traceback containing the exception.
Notes:
This method can be useful to override to change the default
handling of errors.  By default, the error message is sent to
the character who last updated the callback, if connected.
If not, display to the everror channel.'

def handle_error(self, callback, trace):

    callback_name = callback['name']
    number = callback['number']
    obj = callback['obj']
    oid = obj.id
    logger.log_err('An    error    occurred    during    the    callback    {}    of    {}    (#{}),    number    {}\n{}'.format(callback_name, obj, oid, (number + 1), '\n'.join(trace)))
    line = '|runknown|n'
    lineno = '|runknown|n'
    for error in trace:
        if error.startswith('        File    "<string>",    line    '):
            res = RE_LINE_ERROR.search(error)
            if res:
                lineno = int(res.group(1))
                try:
                    line = raw(callback['code'].splitlines()[(lineno - 1)])
                except IndexError:
                    continue
                else:
                    break
    exc = raw(trace[(-1)].strip('\n').splitlines()[(-1)])
    err_msg = 'Error    in    {}    of    {}    (#{})[{}],    line    {}:    {}\n{}'.format(callback_name, obj, oid, (number + 1), lineno, line, exc)
    updater = callback.get('updated_by')
    if (updater is None):
        updater = callback['created_by']
    if (updater and updater.sessions.all()):
        updater.msg(err_msg)
    else:
        err_msg = 'Error    in    {}    of    {}    (#{})[{}],    line    {}:    {}\n                                        {}'.format(callback_name, obj, oid, (number + 1), lineno, line, exc)
        self.ndb.channel.msg(err_msg)
