---
source: crates/ruff_linter/src/rules/flake8_errmsg/mod.rs
---
EM101 [*] Exception must not use a string literal, assign to variable first
 --> EM.py:5:24
  |
4 | def f_a():
5 |     raise RuntimeError("This is an example exception")
  |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
help: Assign to variable; remove string literal
  |
4 | def f_a():
  -     raise RuntimeError("This is an example exception")
5 +     msg = "This is an example exception"
6 +     raise RuntimeError(msg)
7 |
  |
note: This is an unsafe fix and may change runtime behavior

EM101 [*] Exception must not use a string literal, assign to variable first
 --> EM.py:9:24
  |
8 | def f_a_short():
9 |     raise RuntimeError("Error")
  |                        ^^^^^^^
  |
help: Assign to variable; remove string literal
   |
8  | def f_a_short():
   -     raise RuntimeError("Error")
9  +     msg = "Error"
10 +     raise RuntimeError(msg)
11 |
   |
note: This is an unsafe fix and may change runtime behavior

EM101 [*] Exception must not use a string literal, assign to variable first
  --> EM.py:13:24
   |
12 | def f_a_empty():
13 |     raise RuntimeError("")
   |                        ^^
   |
help: Assign to variable; remove string literal
   |
12 | def f_a_empty():
   -     raise RuntimeError("")
13 +     msg = ""
14 +     raise RuntimeError(msg)
15 |
   |
note: This is an unsafe fix and may change runtime behavior

EM102 [*] Exception must not use an f-string literal, assign to variable first
  --> EM.py:18:24
   |
16 | def f_b():
17 |     example = "example"
18 |     raise RuntimeError(f"This is an {example} exception")
   |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
help: Assign to variable; remove f-string literal
   |
17 |     example = "example"
   -     raise RuntimeError(f"This is an {example} exception")
18 +     msg = f"This is an {example} exception"
19 +     raise RuntimeError(msg)
20 |
   |
note: This is an unsafe fix and may change runtime behavior

EM103 [*] Exception must not use a `.format()` string directly, assign to variable first
  --> EM.py:22:24
   |
21 | def f_c():
22 |     raise RuntimeError("This is an {example} exception".format(example="example"))
   |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
help: Assign to variable; remove `.format()` string
   |
21 | def f_c():
   -     raise RuntimeError("This is an {example} exception".format(example="example"))
22 +     msg = "This is an {example} exception".format(example="example")
23 +     raise RuntimeError(msg)
24 |
   |
note: This is an unsafe fix and may change runtime behavior

EM101 [*] Exception must not use a string literal, assign to variable first
  --> EM.py:32:24
   |
30 | def f_msg_defined():
31 |     msg = "hello"
32 |     raise RuntimeError("This is an example exception")
   |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
help: Assign to variable; remove string literal
   |
31 |     msg = "hello"
   -     raise RuntimeError("This is an example exception")
32 +     msg_0 = "This is an example exception"
33 +     raise RuntimeError(msg_0)
34 |
   |
note: This is an unsafe fix and may change runtime behavior

EM101 [*] Exception must not use a string literal, assign to variable first
  --> EM.py:39:24
   |
37 |         msg = "hello"
38 |
39 |     raise RuntimeError("This is an example exception")
   |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
help: Assign to variable; remove string literal
   |
38 |
   -     raise RuntimeError("This is an example exception")
39 +     msg = "This is an example exception"
40 +     raise RuntimeError(msg)
41 |
   |
note: This is an unsafe fix and may change runtime behavior

EM101 [*] Exception must not use a string literal, assign to variable first
  --> EM.py:46:28
   |
45 |     def nested():
46 |         raise RuntimeError("This is an example exception")
   |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
help: Assign to variable; remove string literal
   |
45 |     def nested():
   -         raise RuntimeError("This is an example exception")
46 +         msg_0 = "This is an example exception"
47 +         raise RuntimeError(msg_0)
48 |
   |
note: This is an unsafe fix and may change runtime behavior

EM101 [*] Exception must not use a string literal, assign to variable first
  --> EM.py:51:28
   |
49 | def f_fix_indentation_check(foo):
50 |     if foo:
51 |         raise RuntimeError("This is an example exception")
   |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
52 |     else:
53 |         if foo == "foo":
   |
help: Assign to variable; remove string literal
   |
50 |     if foo:
   -         raise RuntimeError("This is an example exception")
51 +         msg = "This is an example exception"
52 +         raise RuntimeError(msg)
53 |     else:
   |
note: This is an unsafe fix and may change runtime behavior

EM102 [*] Exception must not use an f-string literal, assign to variable first
  --> EM.py:54:32
   |
52 |     else:
53 |         if foo == "foo":
54 |             raise RuntimeError(f"This is an exception: {foo}")
   |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
55 |     raise RuntimeError("This is an exception: {}".format(foo))
   |
help: Assign to variable; remove f-string literal
   |
53 |         if foo == "foo":
   -             raise RuntimeError(f"This is an exception: {foo}")
54 +             msg = f"This is an exception: {foo}"
55 +             raise RuntimeError(msg)
56 |     raise RuntimeError("This is an exception: {}".format(foo))
   |
note: This is an unsafe fix and may change runtime behavior

EM103 [*] Exception must not use a `.format()` string directly, assign to variable first
  --> EM.py:55:24
   |
53 |         if foo == "foo":
54 |             raise RuntimeError(f"This is an exception: {foo}")
55 |     raise RuntimeError("This is an exception: {}".format(foo))
   |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
help: Assign to variable; remove `.format()` string
   |
54 |             raise RuntimeError(f"This is an exception: {foo}")
   -     raise RuntimeError("This is an exception: {}".format(foo))
55 +     msg = "This is an exception: {}".format(foo)
56 +     raise RuntimeError(msg)
57 |
   |
note: This is an unsafe fix and may change runtime behavior

EM101 Exception must not use a string literal, assign to variable first
  --> EM.py:59:28
   |
58 | # Report these, but don't fix them
59 | if foo: raise RuntimeError("This is an example exception")
   |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
60 | if foo: x = 1; raise RuntimeError("This is an example exception")
   |
help: Assign to variable; remove string literal

EM101 Exception must not use a string literal, assign to variable first
  --> EM.py:60:35
   |
58 | # Report these, but don't fix them
59 | if foo: raise RuntimeError("This is an example exception")
60 | if foo: x = 1; raise RuntimeError("This is an example exception")
   |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
help: Assign to variable; remove string literal

EM102 [*] Exception must not use an f-string literal, assign to variable first
  --> EM.py:64:24
   |
63 | def f_triple_quoted_string():
64 |     raise RuntimeError(f"""This is an {"example"} exception""")
   |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
help: Assign to variable; remove f-string literal
   |
63 | def f_triple_quoted_string():
   -     raise RuntimeError(f"""This is an {"example"} exception""")
64 +     msg = f"""This is an {"example"} exception"""
65 +     raise RuntimeError(msg)
66 |
   |
note: This is an unsafe fix and may change runtime behavior

EM101 [*] Exception must not use a string literal, assign to variable first
  --> EM.py:69:9
   |
67 |   def f_multi_line_string():
68 |       raise RuntimeError(
69 | /         "first"
70 | |         "second"
   | |________________^
71 |       )
   |
help: Assign to variable; remove string literal
   |
67 | def f_multi_line_string():
   -     raise RuntimeError(
68 +     msg = (
69 |         "first"
70 |         "second"
71 |     )
72 +     raise RuntimeError(
73 +         msg
74 +     )
75 |
   |
note: This is an unsafe fix and may change runtime behavior

EM103 [*] Exception must not use a `.format()` string directly, assign to variable first
  --> EM.py:76:9
   |
74 |   def f_multi_line_string2():
75 |       raise RuntimeError(
76 | /         "This is an {example} exception".format(
77 | |             example="example"
78 | |         )
   | |_________^
79 |       )
   |
help: Assign to variable; remove `.format()` string
   |
74 | def f_multi_line_string2():
   -     raise RuntimeError(
75 +     msg = (
76 |         "This is an {example} exception".format(
77 |             example="example"
78 |         )
79 |     )
80 +     raise RuntimeError(
81 +         msg
82 +     )
83 |
   |
note: This is an unsafe fix and may change runtime behavior

EM103 [*] Exception must not use a `.format()` string directly, assign to variable first
  --> EM.py:84:9
   |
82 |   def f_multi_line_string2():
83 |       raise RuntimeError(
84 | /         (
85 | |             "This is an "
86 | |             "{example} exception"
87 | |         ).format(
88 | |             example="example"
89 | |         )
   | |_________^
90 |       )
   |
help: Assign to variable; remove `.format()` string
   |
82 | def f_multi_line_string2():
   -     raise RuntimeError(
83 +     msg = (
84 |         (
--------------------------------------------------------------------------------
90 |     )
91 +     raise RuntimeError(
92 +         msg
93 +     )
94 |
   |
note: This is an unsafe fix and may change runtime behavior

EM101 [*] Exception must not use a string literal, assign to variable first
   --> EM.py:118:28
    |
116 |     msg = "."
117 |     try:
118 |         raise RuntimeError("!")
    |                            ^^^
119 |     except RuntimeError:
120 |         return msg
    |
help: Assign to variable; remove string literal
    |
117 |     try:
    -         raise RuntimeError("!")
118 +         msg_0 = "!"
119 +         raise RuntimeError(msg_0)
120 |     except RuntimeError:
    |
note: This is an unsafe fix and may change runtime behavior
