|
25 | 25 |
|
26 | 26 | from pgadmin.utils import u_encode, file_quote, fs_encoding, \ |
27 | 27 | get_complete_file_path, get_storage_directory, IS_WIN |
28 | | -from pgadmin.utils.constants import KERBEROS |
| 28 | +from pgadmin.utils.constants import (KERBEROS, UTILITIES_ARRAY, |
| 29 | + BG_PROCESS_ERROR_MSGS) |
29 | 30 | from pgadmin.utils.locker import ConnectionLocker |
30 | 31 | from pgadmin.utils.preferences import Preferences |
31 | 32 |
|
|
45 | 46 | PROCESS_NOT_FOUND = _("Could not find a process with the specified ID.") |
46 | 47 |
|
47 | 48 |
|
| 49 | +def get_error_msg(cmd, error_code): |
| 50 | + """ |
| 51 | + This function is used to get the error message based on exit code. |
| 52 | + """ |
| 53 | + error_str = '' |
| 54 | + # Get the Utility from the cmd. |
| 55 | + for utility in UTILITIES_ARRAY: |
| 56 | + if utility in cmd: |
| 57 | + error_str = utility + _(': error: ') |
| 58 | + break |
| 59 | + |
| 60 | + try: |
| 61 | + error_str = error_str + BG_PROCESS_ERROR_MSGS[error_code] |
| 62 | + except KeyError: |
| 63 | + error_str = (error_str + _('utility failed with exit code: ') + |
| 64 | + str(error_code)) |
| 65 | + |
| 66 | + return error_str |
| 67 | + |
| 68 | + |
48 | 69 | def get_current_time(format='%Y-%m-%d %H:%M:%S.%f %z'): |
49 | 70 | """ |
50 | 71 | Generate the current time string in the given format. |
@@ -608,6 +629,12 @@ def status(self, out=0, err=0): |
608 | 629 | 'process_state': self.process_state |
609 | 630 | } |
610 | 631 |
|
| 632 | + # Get the error message based on exit code. |
| 633 | + if err_completed and self.ecode != 0: |
| 634 | + err_msg = get_error_msg(self.cmd, self.ecode) |
| 635 | + # This should be the last line as added 'Z' for sorting. |
| 636 | + stderr.append(['Z', err_msg]) |
| 637 | + |
611 | 638 | return { |
612 | 639 | 'out': { |
613 | 640 | 'pos': out, |
|
0 commit comments