MCPcopy
hub / github.com/psycopg/psycopg / error_message

Function error_message

psycopg/psycopg/pq/misc.py:79–95  ·  view source on GitHub ↗

Return an error message from a `PGconn`, `PGresult`, `PGcancelConn`. The return value is a `!str` (unlike pq data which is usually `!bytes`): use the connection encoding if available, otherwise the `!encoding` parameter as a fallback for decoding. Don't raise exceptions on decoding

(
    obj: abc.PGconn | abc.PGresult | abc.PGcancelConn, encoding: str = ""
)

Source from the content-addressed store, hash-verified

77
78
79def error_message(
80 obj: abc.PGconn | abc.PGresult | abc.PGcancelConn, encoding: str = ""
81) -> str:
82 """
83 Return an error message from a `PGconn`, `PGresult`, `PGcancelConn`.
84
85 The return value is a `!str` (unlike pq data which is usually `!bytes`):
86 use the connection encoding if available, otherwise the `!encoding`
87 parameter as a fallback for decoding. Don't raise exceptions on decoding
88 errors.
89 """
90 # Note: this function is exposed by the pq module and was documented, therefore
91 # we are not going to remove it, but we don't use it internally.
92
93 # Don't pass the encoding if not specified, because different classes have
94 # different defaults (conn has its own encoding. others default to utf8).
95 return obj.get_error_message(encoding) if encoding else obj.get_error_message()
96
97
98# Possible prefixes to strip for error messages, in the known localizations.

Callers

nothing calls this directly

Calls 1

get_error_messageMethod · 0.45

Tested by

no test coverage detected