Test Failed
Push — develop ( 720679...ba0508 )
by Dean
02:45
created

ErrorStorage.emit()   B

Complexity

Conditions 5

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 16
ccs 0
cts 7
cp 0
rs 8.5454
c 1
b 0
f 0
cc 5
crap 30
1
from plugin.managers.exception import ExceptionManager
2
3
from exception_wrappers import DisabledError
4
import logging
5
6
log = logging.getLogger(__name__)
7
8
9
class ErrorStorage(logging.Handler):
10
    def __init__(self):
11
        super(ErrorStorage, self).__init__()
12
13
    def emit(self, record):
14
        if record.levelno < logging.ERROR:
15
            return
16
17
        try:
18
            if record.exc_info:
19
                ExceptionManager.create.from_exc_info(record.exc_info)
20
                return
21
22
            self.format(record)
23
24
            ExceptionManager.create.from_message(record.message)
0 ignored issues
show
Bug introduced by
It seems like a value for argument message is missing in the unbound method call.
Loading history...
25
        except DisabledError:
0 ignored issues
show
Unused Code introduced by
This except handler seems to be unused and could be removed.

Except handlers which only contain pass and do not have an else clause can usually simply be removed:

try:
    raises_exception()
except:  # Could be removed
    pass
Loading history...
26
            pass
27
        except Exception as ex:
0 ignored issues
show
Best Practice introduced by
Catching very general exceptions such as Exception is usually not recommended.

Generally, you would want to handle very specific errors in the exception handler. This ensure that you do not hide other types of errors which should be fixed.

So, unless you specifically plan to handle any error, consider adding a more specific exception.

Loading history...
28
            log.warn('Unable to store exception message: %s', ex, exc_info=True)
29
30
ERROR_STORAGE_HANDLER = ErrorStorage()
31