diff --git a/web/pgAdmin4.py b/web/pgAdmin4.py index ce257ef8a..04c4ffeaa 100644 --- a/web/pgAdmin4.py +++ b/web/pgAdmin4.py @@ -15,7 +15,8 @@ to start a web server.""" import sys if sys.version_info < (3, 4): - raise Exception('This application must be run under Python 3.4 or later.') + raise RuntimeError('This application must be run under Python 3.4 ' + 'or later.') import builtins import os @@ -163,7 +164,7 @@ def main(): "To run the app ensure that yarn install command runs " "successfully" ) - raise Exception("No generated javascript, aborting") + raise RuntimeError("No generated javascript, aborting") # Output a startup message if we're not under the runtime and startup. # If we're under WSGI, we don't need to worry about this diff --git a/web/pgadmin/__init__.py b/web/pgadmin/__init__.py index 96a88257c..915c286ad 100644 --- a/web/pgadmin/__init__.py +++ b/web/pgadmin/__init__.py @@ -340,7 +340,8 @@ def create_app(app_name=None): raise FileNotFoundError( 'SQLite database file "' + SQLITE_PATH + '" does not exists.') - raise Exception('Specified SQLite database file is not valid.') + raise RuntimeError('Specified SQLite database file ' + 'is not valid.') else: schema_version = get_version() diff --git a/web/pgadmin/browser/server_groups/servers/types.py b/web/pgadmin/browser/server_groups/servers/types.py index ad01c46bd..7decfdc04 100644 --- a/web/pgadmin/browser/server_groups/servers/types.py +++ b/web/pgadmin/browser/server_groups/servers/types.py @@ -13,6 +13,7 @@ import sys from flask import render_template from flask_babelex import gettext as _ from pgadmin.utils.preferences import Preferences +from werkzeug.exceptions import InternalServerError import config @@ -114,7 +115,7 @@ class ServerType(object): elif operation == 'sql': res = 'psql' else: - raise Exception( + raise InternalServerError( _("Could not find the utility for the operation '%s'").format( operation ) diff --git a/web/pgadmin/feature_tests/file_manager_test.py b/web/pgadmin/feature_tests/file_manager_test.py index de945eeb4..1045512b9 100644 --- a/web/pgadmin/feature_tests/file_manager_test.py +++ b/web/pgadmin/feature_tests/file_manager_test.py @@ -150,8 +150,8 @@ class CheckFileManagerFeatureTest(BaseFeatureTest): "#contents th[data-column='0'].tablesorter-headerAsc")) if not success: - raise Exception("Unable to sort in ascending order while clicked " - "on 'Name' column") + raise RuntimeError("Unable to sort in ascending order while " + "clicked on 'Name' column") # Added time.sleep so that the element to be clicked. time.sleep(0.05) @@ -165,7 +165,7 @@ class CheckFileManagerFeatureTest(BaseFeatureTest): "#contents th[data-column='0'].tablesorter-headerDesc")) if not success: - raise Exception("Unable to sort in descending order while clicked " - "on 'Name' column") + raise RuntimeError("Unable to sort in descending order while " + "clicked on 'Name' column") self.page.click_modal('Cancel') diff --git a/web/pgadmin/feature_tests/query_tool_auto_complete_tests.py b/web/pgadmin/feature_tests/query_tool_auto_complete_tests.py index e45f16055..6bf40754b 100644 --- a/web/pgadmin/feature_tests/query_tool_auto_complete_tests.py +++ b/web/pgadmin/feature_tests/query_tool_auto_complete_tests.py @@ -190,5 +190,5 @@ class QueryToolAutoCompleteFeatureTest(BaseFeatureTest): print("Single entry..........") if expected_string not in code_mirror_text: print("single entry exception.........") - raise Exception("Required String %s is not " - "present" % expected_string) + raise RuntimeError("Required String %s is not " + "present" % expected_string) diff --git a/web/pgadmin/feature_tests/xss_checks_pgadmin_debugger_test.py b/web/pgadmin/feature_tests/xss_checks_pgadmin_debugger_test.py index f0cbf9aff..497a7268b 100644 --- a/web/pgadmin/feature_tests/xss_checks_pgadmin_debugger_test.py +++ b/web/pgadmin/feature_tests/xss_checks_pgadmin_debugger_test.py @@ -44,7 +44,7 @@ class CheckDebuggerForXssFeatureTest(BaseFeatureTest): if test_utils.does_function_exist(self.server, self.test_db, self.function_name) != 'True': - raise Exception("The required function is not found") + raise RuntimeError("The required function is not found") def runTest(self): self.page.wait_for_spinner_to_disappear() diff --git a/web/pgadmin/misc/__init__.py b/web/pgadmin/misc/__init__.py index a96df4674..c20ce75c3 100644 --- a/web/pgadmin/misc/__init__.py +++ b/web/pgadmin/misc/__init__.py @@ -17,6 +17,7 @@ from pgadmin.utils.csrf import pgCSRFProtect from pgadmin.utils.session import cleanup_session_files from pgadmin.misc.themes import get_all_themes import config +from werkzeug.exceptions import InternalServerError MODULE_NAME = 'misc' diff --git a/web/pgadmin/misc/bgprocess/processes.py b/web/pgadmin/misc/bgprocess/processes.py index efaaf2075..362a931ec 100644 --- a/web/pgadmin/misc/bgprocess/processes.py +++ b/web/pgadmin/misc/bgprocess/processes.py @@ -204,8 +204,8 @@ class BatchProcess(object): if self.stime is not None: if self.etime is None: - raise Exception(_('The process has already been started.')) - raise Exception( + raise RuntimeError(_('The process has already been started.')) + raise RuntimeError( _('The process has already finished and cannot be restarted.') ) diff --git a/web/pgadmin/misc/file_manager/__init__.py b/web/pgadmin/misc/file_manager/__init__.py index 89adacf6e..6a23d58b6 100644 --- a/web/pgadmin/misc/file_manager/__init__.py +++ b/web/pgadmin/misc/file_manager/__init__.py @@ -19,6 +19,7 @@ from urllib.parse import unquote from sys import platform as _platform import config import codecs +from werkzeug.exceptions import InternalServerError import simplejson as json from flask import render_template, Response, session, request as req, \ @@ -694,7 +695,7 @@ class Filemanager(object): # Do not allow user to access outside his storage dir # in server mode. if not orig_path.startswith(in_dir): - raise Exception( + raise InternalServerError( gettext(u"Access denied ({0})").format(path)) return True diff --git a/web/pgadmin/tools/sqleditor/command.py b/web/pgadmin/tools/sqleditor/command.py index d856c62bb..1fa7dfe7a 100644 --- a/web/pgadmin/tools/sqleditor/command.py +++ b/web/pgadmin/tools/sqleditor/command.py @@ -14,6 +14,7 @@ from collections import OrderedDict import six from flask import render_template from flask_babelex import gettext +from werkzeug.exceptions import InternalServerError from pgadmin.utils.ajax import forbidden from pgadmin.utils.driver import get_driver from pgadmin.tools.sqleditor.utils.is_query_resultset_updatable \ @@ -195,7 +196,7 @@ class SQLFilter(object): self.nsp_name = result['rows'][0]['nspname'] self.object_name = result['rows'][0]['relname'] else: - raise Exception(gettext( + raise InternalServerError(gettext( 'Not connected to server or connection with the server ' 'has been closed.') ) @@ -406,7 +407,7 @@ class GridCommand(BaseCommand, SQLFilter, FetchedRowTracker): for row in result['rows']: all_columns.append(row['attname']) else: - raise Exception( + raise InternalServerError( gettext('Not connected to server or connection with the ' 'server has been closed.') ) @@ -552,7 +553,7 @@ class TableCommand(GridCommand): # Remove last character from the string pk_names = pk_names[:-1] else: - raise Exception( + raise InternalServerError( gettext('Not connected to server or connection with the ' 'server has been closed.') ) @@ -649,7 +650,7 @@ class TableCommand(GridCommand): raise ExecuteError(has_oids) else: - raise Exception( + raise InternalServerError( gettext('Not connected to server or connection with the ' 'server has been closed.') ) @@ -1001,7 +1002,7 @@ class QueryToolCommand(BaseCommand, FetchedRowTracker): self.nsp_name = result['rows'][0]['nspname'] self.object_name = result['rows'][0]['relname'] else: - raise Exception(gettext( + raise InternalServerError(gettext( 'Not connected to server or connection with the server ' 'has been closed.') ) diff --git a/web/pgadmin/tools/sqleditor/utils/is_query_resultset_updatable.py b/web/pgadmin/tools/sqleditor/utils/is_query_resultset_updatable.py index 220ca9e91..4270b0289 100644 --- a/web/pgadmin/tools/sqleditor/utils/is_query_resultset_updatable.py +++ b/web/pgadmin/tools/sqleditor/utils/is_query_resultset_updatable.py @@ -24,6 +24,7 @@ from flask import render_template from flask_babelex import gettext from collections import OrderedDict +from werkzeug.exceptions import InternalServerError from pgadmin.tools.sqleditor.utils.get_column_types import get_columns_types from pgadmin.utils.exception import ExecuteError @@ -85,7 +86,7 @@ def is_query_resultset_updatable(conn, sql_path): _set_all_columns_not_editable(columns_info=columns_info) return return_not_updatable() else: - raise Exception( + raise InternalServerError( gettext('Not connected to server or connection with the ' 'server has been closed.') ) diff --git a/web/pgadmin/tools/user_management/__init__.py b/web/pgadmin/tools/user_management/__init__.py index 96cf4016f..07b924eec 100644 --- a/web/pgadmin/tools/user_management/__init__.py +++ b/web/pgadmin/tools/user_management/__init__.py @@ -17,6 +17,7 @@ from flask import render_template, request, \ from flask_babelex import gettext as _ from flask_security import login_required, roles_required, current_user from flask_security.utils import encrypt_password +from werkzeug.exceptions import InternalServerError import config from pgadmin.utils import PgAdminModule @@ -98,7 +99,7 @@ def validate_password(data, new_data): if data['newPassword'] == data['confirmPassword']: new_data['password'] = encrypt_password(data['newPassword']) else: - raise Exception(_("Passwords do not match.")) + raise InternalServerError(_("Passwords do not match.")) def validate_user(data): @@ -115,7 +116,7 @@ def validate_user(data): if email_filter.match(data['email']): new_data['email'] = data['email'] else: - raise Exception(_("Invalid email address.")) + raise InternalServerError(_("Invalid email address.")) if 'role' in data and data['role'] != "": new_data['roles'] = int(data['role']) diff --git a/web/pgadmin/utils/driver/psycopg2/__init__.py b/web/pgadmin/utils/driver/psycopg2/__init__.py index 9d6c5ab64..016e585d7 100644 --- a/web/pgadmin/utils/driver/psycopg2/__init__.py +++ b/web/pgadmin/utils/driver/psycopg2/__init__.py @@ -16,6 +16,7 @@ object. import datetime from flask import session from flask_login import current_user +from werkzeug.exceptions import InternalServerError import psycopg2 from psycopg2.extensions import adapt from threading import Lock @@ -131,7 +132,7 @@ class Driver(BaseDriver): if _version: return _version - raise Exception( + raise InternalServerError( "Driver Version information for psycopg2 is not available!" ) @@ -143,7 +144,7 @@ class Driver(BaseDriver): if version: return version - raise Exception( + raise InternalServerError( "libpq version information is not available!" ) diff --git a/web/pgadmin/utils/driver/psycopg2/server_manager.py b/web/pgadmin/utils/driver/psycopg2/server_manager.py index 742612826..81eb49b23 100644 --- a/web/pgadmin/utils/driver/psycopg2/server_manager.py +++ b/web/pgadmin/utils/driver/psycopg2/server_manager.py @@ -16,6 +16,7 @@ import config from flask import current_app, session from flask_security import current_user from flask_babelex import gettext +from werkzeug.exceptions import InternalServerError from pgadmin.utils import get_complete_file_path from pgadmin.utils.crypto import decrypt @@ -38,6 +39,7 @@ class ServerManager(object): This class contains the information about the given server. And, acts as connection manager for that particular session. """ + _INFORMATION_MSG = gettext("Information is not available.") def __init__(self, server): self.connections = dict() @@ -158,17 +160,17 @@ class ServerManager(object): def major_version(self): if self.sversion is not None: return int(self.sversion / 10000) - raise Exception(gettext("Information is not available.")) + raise InternalServerError(self._INFORMATION_MSG) def minor_version(self): if self.sversion: return int(int(self.sversion / 100) % 100) - raise Exception(gettext("Information is not available.")) + raise InternalServerError(self._INFORMATION_MSG) def patch_version(self): if self.sversion: return int(int(self.sversion / 100) / 100) - raise Exception(gettext("Information is not available.")) + raise InternalServerError(self._INFORMATION_MSG) def connection( self, database=None, conn_id=None, auto_reconnect=True, did=None, diff --git a/web/pgadmin/utils/paths.py b/web/pgadmin/utils/paths.py index 462147cee..efc39a8bd 100644 --- a/web/pgadmin/utils/paths.py +++ b/web/pgadmin/utils/paths.py @@ -13,6 +13,7 @@ import os from flask import current_app, url_for from flask_security import current_user, login_required +from werkzeug.exceptions import InternalServerError @login_required @@ -81,14 +82,14 @@ def init_app(app): if storage_dir and not os.path.isdir(storage_dir): if os.path.exists(storage_dir): - raise Exception( + raise InternalServerError( 'The path specified for the storage directory is not a ' 'directory.' ) os.makedirs(storage_dir, int('700', 8)) if storage_dir and not os.access(storage_dir, os.W_OK | os.R_OK): - raise Exception( + raise InternalServerError( 'The user does not have permission to read and write to the ' 'specified storage directory.' ) diff --git a/web/regression/feature_utils/app_starter.py b/web/regression/feature_utils/app_starter.py index cf418b67b..fda73f9fb 100644 --- a/web/regression/feature_utils/app_starter.py +++ b/web/regression/feature_utils/app_starter.py @@ -58,8 +58,8 @@ class AppStarter: retry_count = retry_count + 1 launch_browser(retry_count) else: - raise Exception('Unable to start python server even after ' - 'retrying 60 times.') + raise RuntimeError('Unable to start python server even ' + 'after retrying 60 times.') if self.driver is not None: launch_browser(0) diff --git a/web/regression/feature_utils/pgadmin_page.py b/web/regression/feature_utils/pgadmin_page.py index 334956409..15d775a12 100644 --- a/web/regression/feature_utils/pgadmin_page.py +++ b/web/regression/feature_utils/pgadmin_page.py @@ -323,7 +323,7 @@ class PgadminPage: attempts -= 1 time.sleep(.4) if attempts == 0: - raise Exception(e) + raise e def click_a_tree_node(self, element_name, list_of_element): """It will click a tree node eg. server, schema, table name etc @@ -892,7 +892,7 @@ class PgadminPage: except Exception as e: time.sleep(.2) if attempt == 2: - raise Exception(e) + raise e # Use send keys if input_keys true, else use javascript to set content if input_keys: backspaces = [Keys.BACKSPACE] * len(field.get_attribute('value')) diff --git a/web/regression/runtests.py b/web/regression/runtests.py index 86c5a0a8e..c49b30860 100644 --- a/web/regression/runtests.py +++ b/web/regression/runtests.py @@ -25,7 +25,7 @@ import time import unittest if sys.version_info < (3, 4): - raise Exception('The test suite must be run under Python 3.4 or later.') + raise RuntimeError('The test suite must be run under Python 3.4 or later.') import builtins