'Called internally when a module causes an error.'

def error(self, trigger=None):

    try:
        trace = traceback.format_exc()
        if (sys.version_info.major < 3):
            trace = trace.decode(u'utf-8', errors=u'xmlcharrefreplace')
        stderr(trace)
        try:
            lines = list(reversed(trace.splitlines()))
            report = [lines[0].strip()]
            for line in lines:
                line = line.strip()
                if line.startswith(u'File    "'):
                    report.append((line[0].lower() + line[1:]))
                    break
            else:
                report.append(u'source    unknown')
            signature = (u'%s    (%s)' % (report[0], report[1]))
            log_filename = os.path.join(self.config.core.logdir, u'exceptions.log')
            with codecs.open(log_filename, u'a', encoding=u'utf-8') as logfile:
                logfile.write((u'Signature:    %s\n' % signature))
                if trigger:
                    logfile.write(u'from    {}    at    {}.    Message    was:    {}\n'.format(trigger.nick, str(datetime.now()), trigger.group(0)))
                logfile.write(trace)
                logfile.write(u'----------------------------------------\n\n')
        except Exception as e:
            stderr(u'Could    not    save    full    traceback!')
            LOGGER.error(u'Could    not    save    traceback    from    %s    to    file:    %s', trigger.sender, str(e))
        if (trigger and self.config.core.reply_errors and (trigger.sender is not None)):
            self.msg(trigger.sender, signature)
        if trigger:
            LOGGER.error(u'Exception    from    {}:    {}    ({})'.format(trigger.sender, str(signature), trigger.raw))
    except Exception as e:
        if (trigger and self.config.core.reply_errors and (trigger.sender is not None)):
            self.msg(trigger.sender, u'Got    an    error.')
        if trigger:
            LOGGER.error(u'Exception    from    {}:    {}    ({})'.format(trigger.sender, str(e), trigger.raw))
