Replace the generic exception class with a more specific one.

This commit is contained in:
Aditya Toshniwal 2020-08-07 12:37:00 +05:30 committed by Akshay Joshi
parent 68a5027d15
commit d6400bbcae
18 changed files with 46 additions and 34 deletions

View File

@ -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

View File

@ -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()

View File

@ -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
)

View File

@ -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')

View File

@ -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)

View File

@ -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()

View File

@ -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'

View File

@ -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.')
)

View File

@ -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

View File

@ -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.')
)

View File

@ -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.')
)

View File

@ -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'])

View File

@ -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!"
)

View File

@ -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,

View File

@ -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.'
)

View File

@ -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)

View File

@ -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'))

View File

@ -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