From 0ef4d9cfbbdd7998d3c8115d85bcb3196038d2e0 Mon Sep 17 00:00:00 2001 From: Akshay Joshi Date: Mon, 2 Jun 2025 19:58:36 +0530 Subject: [PATCH 1/3] Fixed an issue where utilities such as pg_dump and pg_restore failed to log error messages when required dependency files were missing. #7466 --- docs/en_US/release_notes_9_5.rst | 1 + web/pgadmin/misc/bgprocess/processes.py | 28 ++++++++++++++++++++++++- web/pgadmin/utils/constants.py | 8 ++++++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/docs/en_US/release_notes_9_5.rst b/docs/en_US/release_notes_9_5.rst index 3ce9d32c500..a6d0c5412c6 100644 --- a/docs/en_US/release_notes_9_5.rst +++ b/docs/en_US/release_notes_9_5.rst @@ -29,5 +29,6 @@ Bug fixes ********* | `Issue #6118 `_ - Improved PL/pgSQL code folding and support nested blocks. + | `Issue #7466 `_ - Fixed an issue where utilities such as pg_dump and pg_restore failed to log error messages when required dependency files were missing. | `Issue #8032 `_ - Fixed an issue where the Schema Diff Tool incorrectly reported differences due to variations in the order of the privileges. | `Issue #8691 `_ - Fixed an issue in the query tool where using multiple cursors to copy text resulted in only the first line being copied. diff --git a/web/pgadmin/misc/bgprocess/processes.py b/web/pgadmin/misc/bgprocess/processes.py index 4dbf5d8f04b..2dd060e2ba6 100644 --- a/web/pgadmin/misc/bgprocess/processes.py +++ b/web/pgadmin/misc/bgprocess/processes.py @@ -25,7 +25,8 @@ from pgadmin.utils import u_encode, file_quote, fs_encoding, \ get_complete_file_path, get_storage_directory, IS_WIN -from pgadmin.utils.constants import KERBEROS +from pgadmin.utils.constants import (KERBEROS, UTILITIES_ARRAY, + BG_PROCESS_ERROR_MSGS) from pgadmin.utils.locker import ConnectionLocker from pgadmin.utils.preferences import Preferences @@ -45,6 +46,27 @@ PROCESS_NOT_FOUND = _("Could not find a process with the specified ID.") +def set_error_msg(cmd, error_code, stderr): + """ + This function is used to set the error message based on + exit code if stderr is empty. + """ + error_str = '' + # Get the Utility from the cmd. + for utility in UTILITIES_ARRAY: + if utility in cmd: + error_str = utility + _(': error: ') + break + + try: + error_str = error_str + BG_PROCESS_ERROR_MSGS[error_code] + except KeyError: + error_str = (error_str + _('utility failed with exit code: ') + + str(error_code)) + + stderr.append([error_code, error_str]) + + def get_current_time(format='%Y-%m-%d %H:%M:%S.%f %z'): """ Generate the current time string in the given format. @@ -608,6 +630,10 @@ def status(self, out=0, err=0): 'process_state': self.process_state } + # Set error message based on exit code if stderr is empty. + if err_completed and len(stderr) == 0: + set_error_msg(self.cmd, self.ecode, stderr) + return { 'out': { 'pos': out, diff --git a/web/pgadmin/utils/constants.py b/web/pgadmin/utils/constants.py index 2ee65944186..aa53675e261 100644 --- a/web/pgadmin/utils/constants.py +++ b/web/pgadmin/utils/constants.py @@ -115,7 +115,13 @@ ] } -UTILITIES_ARRAY = ['pg_dump', 'pg_dumpall', 'pg_restore', 'psql'] +UTILITIES_ARRAY = ['pg_dumpall', 'pg_dump', 'pg_restore', 'psql'] + +BG_PROCESS_ERROR_MSGS = { + 3221225781: gettext('Unable to find a dll needed by the utility. Ensuring ' + '.dll files needed by the utility are in the same ' + 'folder as your executable.') +} ENTER_EMAIL_ADDRESS = "Email address: " USER_NOT_FOUND = gettext("The specified user ID (%s) could not be found.") From 6b6b59b8cfe260b4786ccde683bba6adda35747c Mon Sep 17 00:00:00 2001 From: Akshay Joshi Date: Tue, 3 Jun 2025 11:29:24 +0530 Subject: [PATCH 2/3] Fixed review comments. --- web/pgadmin/misc/bgprocess/processes.py | 10 +++++----- web/pgadmin/utils/constants.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/web/pgadmin/misc/bgprocess/processes.py b/web/pgadmin/misc/bgprocess/processes.py index 2dd060e2ba6..bce52aa8882 100644 --- a/web/pgadmin/misc/bgprocess/processes.py +++ b/web/pgadmin/misc/bgprocess/processes.py @@ -46,10 +46,9 @@ PROCESS_NOT_FOUND = _("Could not find a process with the specified ID.") -def set_error_msg(cmd, error_code, stderr): +def get_error_msg(cmd, error_code): """ - This function is used to set the error message based on - exit code if stderr is empty. + This function is used to get the error message based on exit code. """ error_str = '' # Get the Utility from the cmd. @@ -64,7 +63,7 @@ def set_error_msg(cmd, error_code, stderr): error_str = (error_str + _('utility failed with exit code: ') + str(error_code)) - stderr.append([error_code, error_str]) + return error_str def get_current_time(format='%Y-%m-%d %H:%M:%S.%f %z'): @@ -632,7 +631,8 @@ def status(self, out=0, err=0): # Set error message based on exit code if stderr is empty. if err_completed and len(stderr) == 0: - set_error_msg(self.cmd, self.ecode, stderr) + err_msg = get_error_msg(self.cmd, self.ecode) + stderr.append([self.ecode, err_msg]) return { 'out': { diff --git a/web/pgadmin/utils/constants.py b/web/pgadmin/utils/constants.py index aa53675e261..ed2941ec883 100644 --- a/web/pgadmin/utils/constants.py +++ b/web/pgadmin/utils/constants.py @@ -118,7 +118,7 @@ UTILITIES_ARRAY = ['pg_dumpall', 'pg_dump', 'pg_restore', 'psql'] BG_PROCESS_ERROR_MSGS = { - 3221225781: gettext('Unable to find a dll needed by the utility. Ensuring ' + 3221225781: gettext('Unable to find a dll needed by the utility. Ensure ' '.dll files needed by the utility are in the same ' 'folder as your executable.') } From 48eca6cc305dd3e84849c6157ebb723ef1a410a8 Mon Sep 17 00:00:00 2001 From: Akshay Joshi Date: Tue, 3 Jun 2025 12:58:01 +0530 Subject: [PATCH 3/3] Added log message if process failed with exit code. --- web/pgadmin/misc/bgprocess/processes.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/web/pgadmin/misc/bgprocess/processes.py b/web/pgadmin/misc/bgprocess/processes.py index bce52aa8882..4edda6f91fb 100644 --- a/web/pgadmin/misc/bgprocess/processes.py +++ b/web/pgadmin/misc/bgprocess/processes.py @@ -629,10 +629,11 @@ def status(self, out=0, err=0): 'process_state': self.process_state } - # Set error message based on exit code if stderr is empty. - if err_completed and len(stderr) == 0: + # Get the error message based on exit code. + if err_completed and self.ecode != 0: err_msg = get_error_msg(self.cmd, self.ecode) - stderr.append([self.ecode, err_msg]) + # This should be the last line as added 'Z' for sorting. + stderr.append(['Z', err_msg]) return { 'out': {