no-str-exception-translation¶
Forbid translated exceptions from reusing a caught exception’s rendered message.
Message¶
Use a fixed message when translating an exception, and preserve the cause with raise ... from exc.
Valid examples¶
try:
run()
except ValueError as exc:
raise CommandArgumentError("Invalid resource identifier.") from exc
message = str(value)
Show more
try:
run()
except ValueError as exc:
str = lambda value: "fixed"
raise RuntimeError(str(exc)) from exc
error = "fixed"
try:
run()
except ValueError as exc:
def capture() -> None:
error = exc
raise RuntimeError(str(error)) from exc
Invalid examples¶
try:
run()
except ValueError as exc:
raise CommandArgumentError(str(exc)) from exc
Show more
try:
run()
except ValueError as error:
raise RuntimeError(str(error)) from error
try:
run()
except ValueError as exc:
raise RuntimeError(message=str(exc)) from exc
try:
run()
except ValueError as exc:
raise RuntimeError(f"{exc}") from exc
try:
run()
except ValueError as exc:
raise RuntimeError("{}".format(exc)) from exc
try:
run()
except ValueError as exc:
raise RuntimeError("%s" % exc) from exc
try:
run()
except ValueError as exc:
raise RuntimeError("%s" % (exc,)) from exc
import builtins
try:
run()
except ValueError as exc:
raise RuntimeError(builtins.str(exc)) from exc
import builtins as builtin_values
try:
run()
except ValueError as exc:
raise RuntimeError(builtin_values.str(exc)) from exc
from builtins import str as stringify
try:
run()
except ValueError as exc:
raise RuntimeError(stringify(exc)) from exc