---
source: crates/ruff_linter/src/rules/tryceratops/mod.rs
---
TRY400.py:13:9: TRY400 [*] Use `logging.exception` instead of `logging.error`
   |
11 |         a = 1
12 |     except Exception:
13 |         logging.error("Context message here")
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY400
14 | 
15 |         if True:
   |
   = help: Replace with `exception`

ℹ Safe fix
10 10 |     try:
11 11 |         a = 1
12 12 |     except Exception:
13    |-        logging.error("Context message here")
   13 |+        logging.exception("Context message here")
14 14 | 
15 15 |         if True:
16 16 |             logging.error("Context message here")

TRY400.py:16:13: TRY400 [*] Use `logging.exception` instead of `logging.error`
   |
15 |         if True:
16 |             logging.error("Context message here")
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY400
   |
   = help: Replace with `exception`

ℹ Safe fix
13 13 |         logging.error("Context message here")
14 14 | 
15 15 |         if True:
16    |-            logging.error("Context message here")
   16 |+            logging.exception("Context message here")
17 17 | 
18 18 | 
19 19 | def bad():

TRY400.py:27:9: TRY400 [*] Use `logging.exception` instead of `logging.error`
   |
25 |         a = 1
26 |     except Exception:
27 |         logger.error("Context message here")
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY400
28 | 
29 |         if True:
   |
   = help: Replace with `exception`

ℹ Unsafe fix
24 24 |     try:
25 25 |         a = 1
26 26 |     except Exception:
27    |-        logger.error("Context message here")
   27 |+        logger.exception("Context message here")
28 28 | 
29 29 |         if True:
30 30 |             logger.error("Context message here")

TRY400.py:30:13: TRY400 [*] Use `logging.exception` instead of `logging.error`
   |
29 |         if True:
30 |             logger.error("Context message here")
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY400
   |
   = help: Replace with `exception`

ℹ Unsafe fix
27 27 |         logger.error("Context message here")
28 28 | 
29 29 |         if True:
30    |-            logger.error("Context message here")
   30 |+            logger.exception("Context message here")
31 31 | 
32 32 | 
33 33 | def bad():

TRY400.py:37:9: TRY400 [*] Use `logging.exception` instead of `logging.error`
   |
35 |         a = 1
36 |     except Exception:
37 |         log.error("Context message here")
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY400
38 | 
39 |         if True:
   |
   = help: Replace with `exception`

ℹ Unsafe fix
34 34 |     try:
35 35 |         a = 1
36 36 |     except Exception:
37    |-        log.error("Context message here")
   37 |+        log.exception("Context message here")
38 38 | 
39 39 |         if True:
40 40 |             log.error("Context message here")

TRY400.py:40:13: TRY400 [*] Use `logging.exception` instead of `logging.error`
   |
39 |         if True:
40 |             log.error("Context message here")
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY400
   |
   = help: Replace with `exception`

ℹ Unsafe fix
37 37 |         log.error("Context message here")
38 38 | 
39 39 |         if True:
40    |-            log.error("Context message here")
   40 |+            log.exception("Context message here")
41 41 | 
42 42 | 
43 43 | def bad():

TRY400.py:47:9: TRY400 [*] Use `logging.exception` instead of `logging.error`
   |
45 |         a = 1
46 |     except Exception:
47 |         self.logger.error("Context message here")
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY400
48 | 
49 |         if True:
   |
   = help: Replace with `exception`

ℹ Unsafe fix
44 44 |     try:
45 45 |         a = 1
46 46 |     except Exception:
47    |-        self.logger.error("Context message here")
   47 |+        self.logger.exception("Context message here")
48 48 | 
49 49 |         if True:
50 50 |             self.logger.error("Context message here")

TRY400.py:50:13: TRY400 [*] Use `logging.exception` instead of `logging.error`
   |
49 |         if True:
50 |             self.logger.error("Context message here")
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY400
   |
   = help: Replace with `exception`

ℹ Unsafe fix
47 47 |         self.logger.error("Context message here")
48 48 | 
49 49 |         if True:
50    |-            self.logger.error("Context message here")
   50 |+            self.logger.exception("Context message here")
51 51 | 
52 52 | 
53 53 | def good():

TRY400.py:100:9: TRY400 [*] Use `logging.exception` instead of `logging.error`
    |
 98 |         a = 1
 99 |     except Exception:
100 |         error("Context message here")
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY400
101 | 
102 |         if True:
    |
    = help: Replace with `exception`

ℹ Safe fix
97  97  |     try:
98  98  |         a = 1
99  99  |     except Exception:
100     |-        error("Context message here")
    100 |+        exception("Context message here")
101 101 | 
102 102 |         if True:
103 103 |             error("Context message here")

TRY400.py:103:13: TRY400 [*] Use `logging.exception` instead of `logging.error`
    |
102 |         if True:
103 |             error("Context message here")
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY400
    |
    = help: Replace with `exception`

ℹ Safe fix
100 100 |         error("Context message here")
101 101 | 
102 102 |         if True:
103     |-            error("Context message here")
    103 |+            exception("Context message here")
104 104 | 
105 105 | 
106 106 | def good():

TRY400.py:143:13: TRY400 [*] Use `logging.exception` instead of `logging.error`
    |
141 |             b = 2
142 |         except Exception:
143 |             error("Context message here")
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY400
    |
    = help: Replace with `exception`

ℹ Safe fix
140 140 |         try:
141 141 |             b = 2
142 142 |         except Exception:
143     |-            error("Context message here")
    143 |+            exception("Context message here")
