Skip to content

Commit

Permalink
Modified logic for formatted exception message. #8165
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay-joshi committed Jan 3, 2025
1 parent 6d45dd4 commit 90cdeef
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
1 change: 1 addition & 0 deletions docs/en_US/release_notes_9_0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ Bug fixes
| `Issue #8255 <https://github.com/pgadmin-org/pgadmin4/issues/8255>`_ - Fixed an issue where tooltip on a dropdown button is blocking access to dropdown menu.
| `Issue #8256 <https://github.com/pgadmin-org/pgadmin4/issues/8256>`_ - Fix the error occurring while loading preferences on startup.
| `Issue #8273 <https://github.com/pgadmin-org/pgadmin4/issues/8273>`_ - Fixed an issue where copying query tool output cell is not working if any SQL text is selected.
| `Issue #8299 <https://github.com/pgadmin-org/pgadmin4/issues/8299>`_ - Ensure master password pop up is not shown on setting MASTER_PASSWORD_REQUIRED to false.
39 changes: 16 additions & 23 deletions web/pgadmin/utils/driver/psycopg3/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1675,26 +1675,23 @@ def _formatted_exception_msg(self, exception_obj, formatted_msg):
message
"""
if hasattr(exception_obj, 'pgerror'):
errmsg = exception_obj.pgerror
elif hasattr(exception_obj, 'diag') and \
hasattr(exception_obj.diag, 'message_detail') and\
exception_obj.diag.message_detail is not None:
errmsg = exception_obj.diag.message_detail + '\n' + \
exception_obj.diag.message_primary
else:
errmsg = str(exception_obj)

# if formatted_msg is false then return from the function
if not formatted_msg:
if hasattr(exception_obj, 'pgerror'):
errmsg = exception_obj.pgerror
elif hasattr(exception_obj, 'diag') and \
hasattr(exception_obj.diag, 'message_detail') and\
exception_obj.diag.message_detail is not None:
errmsg = (exception_obj.diag.message_primary + '\n' +
exception_obj.diag.message_detail)
else:
errmsg = str(exception_obj)

notices = self.get_notices()
errmsg = errmsg.replace('\n', '<br/>')
return errmsg if notices == '' else notices + '\n' + errmsg

# Do not append if error starts with `ERROR:` as most pg related
# error starts with `ERROR:`
if not errmsg.startswith('ERROR:'):
errmsg = gettext('ERROR: ') + errmsg + ' \n\n'

errmsg = ''
if exception_obj.diag.severity is not None \
and exception_obj.diag.message_primary is not None:
ex_diag_message = "{0}: {1}".format(
Expand All @@ -1717,29 +1714,25 @@ def _formatted_exception_msg(self, exception_obj, formatted_msg):
errmsg += gettext('SQL state: ')
errmsg += exception_obj.diag.sqlstate

if exception_obj.diag.message_detail is not None and \
'Detail:'.lower() not in errmsg.lower():
if exception_obj.diag.message_detail is not None:
if not errmsg.endswith('\n'):
errmsg += '\n'
errmsg += gettext('Detail: ')
errmsg += exception_obj.diag.message_detail

if exception_obj.diag.message_hint is not None and \
'Hint:'.lower() not in errmsg.lower():
if exception_obj.diag.message_hint is not None:
if not errmsg.endswith('\n'):
errmsg += '\n'
errmsg += gettext('Hint: ')
errmsg += exception_obj.diag.message_hint

if exception_obj.diag.statement_position is not None and \
'Character:'.lower() not in errmsg.lower():
if exception_obj.diag.statement_position is not None:
if not errmsg.endswith('\n'):
errmsg += '\n'
errmsg += gettext('Character: ')
errmsg += exception_obj.diag.statement_position

if exception_obj.diag.context is not None and \
'Context:'.lower() not in errmsg.lower():
if exception_obj.diag.context is not None:
if not errmsg.endswith('\n'):
errmsg += '\n'
errmsg += gettext('Context: ')
Expand Down

0 comments on commit 90cdeef

Please sign in to comment.