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 = ""
)
| 77 | |
| 78 | |
| 79 | def 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. |
nothing calls this directly
no test coverage detected