mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2026-09-03 20:52:57 -05:00
Replace the generic exception class with a more specific one.
This commit is contained in:
committed by
Akshay Joshi
parent
68a5027d15
commit
d6400bbcae
+3
-2
@@ -15,7 +15,8 @@ to start a web server."""
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
if sys.version_info < (3, 4):
|
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 builtins
|
||||||
import os
|
import os
|
||||||
@@ -163,7 +164,7 @@ def main():
|
|||||||
"To run the app ensure that yarn install command runs "
|
"To run the app ensure that yarn install command runs "
|
||||||
"successfully"
|
"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.
|
# 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
|
# If we're under WSGI, we don't need to worry about this
|
||||||
|
|||||||
@@ -340,7 +340,8 @@ def create_app(app_name=None):
|
|||||||
raise FileNotFoundError(
|
raise FileNotFoundError(
|
||||||
'SQLite database file "' + SQLITE_PATH +
|
'SQLite database file "' + SQLITE_PATH +
|
||||||
'" does not exists.')
|
'" does not exists.')
|
||||||
raise Exception('Specified SQLite database file is not valid.')
|
raise RuntimeError('Specified SQLite database file '
|
||||||
|
'is not valid.')
|
||||||
else:
|
else:
|
||||||
schema_version = get_version()
|
schema_version = get_version()
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import sys
|
|||||||
from flask import render_template
|
from flask import render_template
|
||||||
from flask_babelex import gettext as _
|
from flask_babelex import gettext as _
|
||||||
from pgadmin.utils.preferences import Preferences
|
from pgadmin.utils.preferences import Preferences
|
||||||
|
from werkzeug.exceptions import InternalServerError
|
||||||
|
|
||||||
import config
|
import config
|
||||||
|
|
||||||
@@ -114,7 +115,7 @@ class ServerType(object):
|
|||||||
elif operation == 'sql':
|
elif operation == 'sql':
|
||||||
res = 'psql'
|
res = 'psql'
|
||||||
else:
|
else:
|
||||||
raise Exception(
|
raise InternalServerError(
|
||||||
_("Could not find the utility for the operation '%s'").format(
|
_("Could not find the utility for the operation '%s'").format(
|
||||||
operation
|
operation
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -150,8 +150,8 @@ class CheckFileManagerFeatureTest(BaseFeatureTest):
|
|||||||
"#contents th[data-column='0'].tablesorter-headerAsc"))
|
"#contents th[data-column='0'].tablesorter-headerAsc"))
|
||||||
|
|
||||||
if not success:
|
if not success:
|
||||||
raise Exception("Unable to sort in ascending order while clicked "
|
raise RuntimeError("Unable to sort in ascending order while "
|
||||||
"on 'Name' column")
|
"clicked on 'Name' column")
|
||||||
# Added time.sleep so that the element to be clicked.
|
# Added time.sleep so that the element to be clicked.
|
||||||
time.sleep(0.05)
|
time.sleep(0.05)
|
||||||
|
|
||||||
@@ -165,7 +165,7 @@ class CheckFileManagerFeatureTest(BaseFeatureTest):
|
|||||||
"#contents th[data-column='0'].tablesorter-headerDesc"))
|
"#contents th[data-column='0'].tablesorter-headerDesc"))
|
||||||
|
|
||||||
if not success:
|
if not success:
|
||||||
raise Exception("Unable to sort in descending order while clicked "
|
raise RuntimeError("Unable to sort in descending order while "
|
||||||
"on 'Name' column")
|
"clicked on 'Name' column")
|
||||||
|
|
||||||
self.page.click_modal('Cancel')
|
self.page.click_modal('Cancel')
|
||||||
|
|||||||
@@ -190,5 +190,5 @@ class QueryToolAutoCompleteFeatureTest(BaseFeatureTest):
|
|||||||
print("Single entry..........")
|
print("Single entry..........")
|
||||||
if expected_string not in code_mirror_text:
|
if expected_string not in code_mirror_text:
|
||||||
print("single entry exception.........")
|
print("single entry exception.........")
|
||||||
raise Exception("Required String %s is not "
|
raise RuntimeError("Required String %s is not "
|
||||||
"present" % expected_string)
|
"present" % expected_string)
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class CheckDebuggerForXssFeatureTest(BaseFeatureTest):
|
|||||||
|
|
||||||
if test_utils.does_function_exist(self.server, self.test_db,
|
if test_utils.does_function_exist(self.server, self.test_db,
|
||||||
self.function_name) != 'True':
|
self.function_name) != 'True':
|
||||||
raise Exception("The required function is not found")
|
raise RuntimeError("The required function is not found")
|
||||||
|
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
self.page.wait_for_spinner_to_disappear()
|
self.page.wait_for_spinner_to_disappear()
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ from pgadmin.utils.csrf import pgCSRFProtect
|
|||||||
from pgadmin.utils.session import cleanup_session_files
|
from pgadmin.utils.session import cleanup_session_files
|
||||||
from pgadmin.misc.themes import get_all_themes
|
from pgadmin.misc.themes import get_all_themes
|
||||||
import config
|
import config
|
||||||
|
from werkzeug.exceptions import InternalServerError
|
||||||
|
|
||||||
MODULE_NAME = 'misc'
|
MODULE_NAME = 'misc'
|
||||||
|
|
||||||
|
|||||||
@@ -204,8 +204,8 @@ class BatchProcess(object):
|
|||||||
|
|
||||||
if self.stime is not None:
|
if self.stime is not None:
|
||||||
if self.etime is None:
|
if self.etime is None:
|
||||||
raise Exception(_('The process has already been started.'))
|
raise RuntimeError(_('The process has already been started.'))
|
||||||
raise Exception(
|
raise RuntimeError(
|
||||||
_('The process has already finished and cannot be restarted.')
|
_('The process has already finished and cannot be restarted.')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ from urllib.parse import unquote
|
|||||||
from sys import platform as _platform
|
from sys import platform as _platform
|
||||||
import config
|
import config
|
||||||
import codecs
|
import codecs
|
||||||
|
from werkzeug.exceptions import InternalServerError
|
||||||
|
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
from flask import render_template, Response, session, request as req, \
|
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
|
# Do not allow user to access outside his storage dir
|
||||||
# in server mode.
|
# in server mode.
|
||||||
if not orig_path.startswith(in_dir):
|
if not orig_path.startswith(in_dir):
|
||||||
raise Exception(
|
raise InternalServerError(
|
||||||
gettext(u"Access denied ({0})").format(path))
|
gettext(u"Access denied ({0})").format(path))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ from collections import OrderedDict
|
|||||||
import six
|
import six
|
||||||
from flask import render_template
|
from flask import render_template
|
||||||
from flask_babelex import gettext
|
from flask_babelex import gettext
|
||||||
|
from werkzeug.exceptions import InternalServerError
|
||||||
from pgadmin.utils.ajax import forbidden
|
from pgadmin.utils.ajax import forbidden
|
||||||
from pgadmin.utils.driver import get_driver
|
from pgadmin.utils.driver import get_driver
|
||||||
from pgadmin.tools.sqleditor.utils.is_query_resultset_updatable \
|
from pgadmin.tools.sqleditor.utils.is_query_resultset_updatable \
|
||||||
@@ -195,7 +196,7 @@ class SQLFilter(object):
|
|||||||
self.nsp_name = result['rows'][0]['nspname']
|
self.nsp_name = result['rows'][0]['nspname']
|
||||||
self.object_name = result['rows'][0]['relname']
|
self.object_name = result['rows'][0]['relname']
|
||||||
else:
|
else:
|
||||||
raise Exception(gettext(
|
raise InternalServerError(gettext(
|
||||||
'Not connected to server or connection with the server '
|
'Not connected to server or connection with the server '
|
||||||
'has been closed.')
|
'has been closed.')
|
||||||
)
|
)
|
||||||
@@ -406,7 +407,7 @@ class GridCommand(BaseCommand, SQLFilter, FetchedRowTracker):
|
|||||||
for row in result['rows']:
|
for row in result['rows']:
|
||||||
all_columns.append(row['attname'])
|
all_columns.append(row['attname'])
|
||||||
else:
|
else:
|
||||||
raise Exception(
|
raise InternalServerError(
|
||||||
gettext('Not connected to server or connection with the '
|
gettext('Not connected to server or connection with the '
|
||||||
'server has been closed.')
|
'server has been closed.')
|
||||||
)
|
)
|
||||||
@@ -552,7 +553,7 @@ class TableCommand(GridCommand):
|
|||||||
# Remove last character from the string
|
# Remove last character from the string
|
||||||
pk_names = pk_names[:-1]
|
pk_names = pk_names[:-1]
|
||||||
else:
|
else:
|
||||||
raise Exception(
|
raise InternalServerError(
|
||||||
gettext('Not connected to server or connection with the '
|
gettext('Not connected to server or connection with the '
|
||||||
'server has been closed.')
|
'server has been closed.')
|
||||||
)
|
)
|
||||||
@@ -649,7 +650,7 @@ class TableCommand(GridCommand):
|
|||||||
raise ExecuteError(has_oids)
|
raise ExecuteError(has_oids)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise Exception(
|
raise InternalServerError(
|
||||||
gettext('Not connected to server or connection with the '
|
gettext('Not connected to server or connection with the '
|
||||||
'server has been closed.')
|
'server has been closed.')
|
||||||
)
|
)
|
||||||
@@ -1001,7 +1002,7 @@ class QueryToolCommand(BaseCommand, FetchedRowTracker):
|
|||||||
self.nsp_name = result['rows'][0]['nspname']
|
self.nsp_name = result['rows'][0]['nspname']
|
||||||
self.object_name = result['rows'][0]['relname']
|
self.object_name = result['rows'][0]['relname']
|
||||||
else:
|
else:
|
||||||
raise Exception(gettext(
|
raise InternalServerError(gettext(
|
||||||
'Not connected to server or connection with the server '
|
'Not connected to server or connection with the server '
|
||||||
'has been closed.')
|
'has been closed.')
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
from flask import render_template
|
from flask import render_template
|
||||||
from flask_babelex import gettext
|
from flask_babelex import gettext
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
from werkzeug.exceptions import InternalServerError
|
||||||
|
|
||||||
from pgadmin.tools.sqleditor.utils.get_column_types import get_columns_types
|
from pgadmin.tools.sqleditor.utils.get_column_types import get_columns_types
|
||||||
from pgadmin.utils.exception import ExecuteError
|
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)
|
_set_all_columns_not_editable(columns_info=columns_info)
|
||||||
return return_not_updatable()
|
return return_not_updatable()
|
||||||
else:
|
else:
|
||||||
raise Exception(
|
raise InternalServerError(
|
||||||
gettext('Not connected to server or connection with the '
|
gettext('Not connected to server or connection with the '
|
||||||
'server has been closed.')
|
'server has been closed.')
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ from flask import render_template, request, \
|
|||||||
from flask_babelex import gettext as _
|
from flask_babelex import gettext as _
|
||||||
from flask_security import login_required, roles_required, current_user
|
from flask_security import login_required, roles_required, current_user
|
||||||
from flask_security.utils import encrypt_password
|
from flask_security.utils import encrypt_password
|
||||||
|
from werkzeug.exceptions import InternalServerError
|
||||||
|
|
||||||
import config
|
import config
|
||||||
from pgadmin.utils import PgAdminModule
|
from pgadmin.utils import PgAdminModule
|
||||||
@@ -98,7 +99,7 @@ def validate_password(data, new_data):
|
|||||||
if data['newPassword'] == data['confirmPassword']:
|
if data['newPassword'] == data['confirmPassword']:
|
||||||
new_data['password'] = encrypt_password(data['newPassword'])
|
new_data['password'] = encrypt_password(data['newPassword'])
|
||||||
else:
|
else:
|
||||||
raise Exception(_("Passwords do not match."))
|
raise InternalServerError(_("Passwords do not match."))
|
||||||
|
|
||||||
|
|
||||||
def validate_user(data):
|
def validate_user(data):
|
||||||
@@ -115,7 +116,7 @@ def validate_user(data):
|
|||||||
if email_filter.match(data['email']):
|
if email_filter.match(data['email']):
|
||||||
new_data['email'] = data['email']
|
new_data['email'] = data['email']
|
||||||
else:
|
else:
|
||||||
raise Exception(_("Invalid email address."))
|
raise InternalServerError(_("Invalid email address."))
|
||||||
|
|
||||||
if 'role' in data and data['role'] != "":
|
if 'role' in data and data['role'] != "":
|
||||||
new_data['roles'] = int(data['role'])
|
new_data['roles'] = int(data['role'])
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ object.
|
|||||||
import datetime
|
import datetime
|
||||||
from flask import session
|
from flask import session
|
||||||
from flask_login import current_user
|
from flask_login import current_user
|
||||||
|
from werkzeug.exceptions import InternalServerError
|
||||||
import psycopg2
|
import psycopg2
|
||||||
from psycopg2.extensions import adapt
|
from psycopg2.extensions import adapt
|
||||||
from threading import Lock
|
from threading import Lock
|
||||||
@@ -131,7 +132,7 @@ class Driver(BaseDriver):
|
|||||||
if _version:
|
if _version:
|
||||||
return _version
|
return _version
|
||||||
|
|
||||||
raise Exception(
|
raise InternalServerError(
|
||||||
"Driver Version information for psycopg2 is not available!"
|
"Driver Version information for psycopg2 is not available!"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -143,7 +144,7 @@ class Driver(BaseDriver):
|
|||||||
if version:
|
if version:
|
||||||
return version
|
return version
|
||||||
|
|
||||||
raise Exception(
|
raise InternalServerError(
|
||||||
"libpq version information is not available!"
|
"libpq version information is not available!"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import config
|
|||||||
from flask import current_app, session
|
from flask import current_app, session
|
||||||
from flask_security import current_user
|
from flask_security import current_user
|
||||||
from flask_babelex import gettext
|
from flask_babelex import gettext
|
||||||
|
from werkzeug.exceptions import InternalServerError
|
||||||
|
|
||||||
from pgadmin.utils import get_complete_file_path
|
from pgadmin.utils import get_complete_file_path
|
||||||
from pgadmin.utils.crypto import decrypt
|
from pgadmin.utils.crypto import decrypt
|
||||||
@@ -38,6 +39,7 @@ class ServerManager(object):
|
|||||||
This class contains the information about the given server.
|
This class contains the information about the given server.
|
||||||
And, acts as connection manager for that particular session.
|
And, acts as connection manager for that particular session.
|
||||||
"""
|
"""
|
||||||
|
_INFORMATION_MSG = gettext("Information is not available.")
|
||||||
|
|
||||||
def __init__(self, server):
|
def __init__(self, server):
|
||||||
self.connections = dict()
|
self.connections = dict()
|
||||||
@@ -158,17 +160,17 @@ class ServerManager(object):
|
|||||||
def major_version(self):
|
def major_version(self):
|
||||||
if self.sversion is not None:
|
if self.sversion is not None:
|
||||||
return int(self.sversion / 10000)
|
return int(self.sversion / 10000)
|
||||||
raise Exception(gettext("Information is not available."))
|
raise InternalServerError(self._INFORMATION_MSG)
|
||||||
|
|
||||||
def minor_version(self):
|
def minor_version(self):
|
||||||
if self.sversion:
|
if self.sversion:
|
||||||
return int(int(self.sversion / 100) % 100)
|
return int(int(self.sversion / 100) % 100)
|
||||||
raise Exception(gettext("Information is not available."))
|
raise InternalServerError(self._INFORMATION_MSG)
|
||||||
|
|
||||||
def patch_version(self):
|
def patch_version(self):
|
||||||
if self.sversion:
|
if self.sversion:
|
||||||
return int(int(self.sversion / 100) / 100)
|
return int(int(self.sversion / 100) / 100)
|
||||||
raise Exception(gettext("Information is not available."))
|
raise InternalServerError(self._INFORMATION_MSG)
|
||||||
|
|
||||||
def connection(
|
def connection(
|
||||||
self, database=None, conn_id=None, auto_reconnect=True, did=None,
|
self, database=None, conn_id=None, auto_reconnect=True, did=None,
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import os
|
|||||||
|
|
||||||
from flask import current_app, url_for
|
from flask import current_app, url_for
|
||||||
from flask_security import current_user, login_required
|
from flask_security import current_user, login_required
|
||||||
|
from werkzeug.exceptions import InternalServerError
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@@ -81,14 +82,14 @@ def init_app(app):
|
|||||||
|
|
||||||
if storage_dir and not os.path.isdir(storage_dir):
|
if storage_dir and not os.path.isdir(storage_dir):
|
||||||
if os.path.exists(storage_dir):
|
if os.path.exists(storage_dir):
|
||||||
raise Exception(
|
raise InternalServerError(
|
||||||
'The path specified for the storage directory is not a '
|
'The path specified for the storage directory is not a '
|
||||||
'directory.'
|
'directory.'
|
||||||
)
|
)
|
||||||
os.makedirs(storage_dir, int('700', 8))
|
os.makedirs(storage_dir, int('700', 8))
|
||||||
|
|
||||||
if storage_dir and not os.access(storage_dir, os.W_OK | os.R_OK):
|
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 '
|
'The user does not have permission to read and write to the '
|
||||||
'specified storage directory.'
|
'specified storage directory.'
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -58,8 +58,8 @@ class AppStarter:
|
|||||||
retry_count = retry_count + 1
|
retry_count = retry_count + 1
|
||||||
launch_browser(retry_count)
|
launch_browser(retry_count)
|
||||||
else:
|
else:
|
||||||
raise Exception('Unable to start python server even after '
|
raise RuntimeError('Unable to start python server even '
|
||||||
'retrying 60 times.')
|
'after retrying 60 times.')
|
||||||
|
|
||||||
if self.driver is not None:
|
if self.driver is not None:
|
||||||
launch_browser(0)
|
launch_browser(0)
|
||||||
|
|||||||
@@ -323,7 +323,7 @@ class PgadminPage:
|
|||||||
attempts -= 1
|
attempts -= 1
|
||||||
time.sleep(.4)
|
time.sleep(.4)
|
||||||
if attempts == 0:
|
if attempts == 0:
|
||||||
raise Exception(e)
|
raise e
|
||||||
|
|
||||||
def click_a_tree_node(self, element_name, list_of_element):
|
def click_a_tree_node(self, element_name, list_of_element):
|
||||||
"""It will click a tree node eg. server, schema, table name etc
|
"""It will click a tree node eg. server, schema, table name etc
|
||||||
@@ -892,7 +892,7 @@ class PgadminPage:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
time.sleep(.2)
|
time.sleep(.2)
|
||||||
if attempt == 2:
|
if attempt == 2:
|
||||||
raise Exception(e)
|
raise e
|
||||||
# Use send keys if input_keys true, else use javascript to set content
|
# Use send keys if input_keys true, else use javascript to set content
|
||||||
if input_keys:
|
if input_keys:
|
||||||
backspaces = [Keys.BACKSPACE] * len(field.get_attribute('value'))
|
backspaces = [Keys.BACKSPACE] * len(field.get_attribute('value'))
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import time
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
if sys.version_info < (3, 4):
|
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
|
import builtins
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user