Skip to content

Commit f08dd03

Browse files
Always raise "DPY-6005: cannot connect to database" and remove the
phrase "cannot connect to database from all other errors".
1 parent 4ff3ad8 commit f08dd03

File tree

3 files changed

+22
-25
lines changed

3 files changed

+22
-25
lines changed

doc/src/release_notes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ Thin Mode Changes
2323
#) Removed internally set fixed size for database collections. Collections of
2424
any size supported by the database can now be created.
2525
#) Improved BOOLEAN handling.
26+
#) Error ``DPY-6005: cannot connect to database`` is now raised for all
27+
failures to connect to the database and the phrase ``cannot connect to
28+
database`` is removed from all other error messages (since this can be
29+
confusing when these errors are raised from
30+
:meth:`ConnectParams.parse_connect_string()`).
2631
#) Fixed bug when calling :meth:`Cursor.executemany()` with PL/SQL when the
2732
size of the bound data increases on subsequent calls
2833
(`issue 132 <https://github.com/oracle/python-oracledb/issues/132>`__).

src/oracledb/errors.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ def _raise_err(error_num: int, context_error_message: str=None,
110110
supplied arguments.
111111
"""
112112
message = _get_error_text(error_num, **args)
113+
if context_error_message is None and cause is not None:
114+
context_error_message = str(cause)
113115
if context_error_message is not None:
114116
message = f"{message}\n{context_error_message}"
115117
exc_type = ERR_EXCEPTION_TYPES[error_num // 1000]
@@ -307,7 +309,7 @@ def _raise_from_string(exc_type: Exception, message: str) -> None:
307309
'column truncated to {col_value_len} {unit}. '
308310
'Untruncated was {actual_len}',
309311
ERR_CONNECTION_FAILED:
310-
'cannot connect to database. Connection failed with "{exception}"',
312+
'cannot connect to database.',
311313
ERR_CONTENT_INVALID_AFTER_NUMBER:
312314
'invalid number (content after number)',
313315
ERR_CURSOR_NOT_OPEN:
@@ -386,25 +388,22 @@ def _raise_from_string(exc_type: Exception, message: str) -> None:
386388
ERR_INVALID_REF_CURSOR:
387389
'invalid REF CURSOR: never opened in PL/SQL',
388390
ERR_INVALID_SERVER_CERT_DN:
389-
'cannot connect to database. The distinguished name (DN) on '
390-
'the server certificate does not match the expected value',
391+
'The distinguished name (DN) on the server certificate does not '
392+
'match the expected value',
391393
ERR_INVALID_SERVER_TYPE:
392394
'invalid server_type: {server_type}',
393395
ERR_INVALID_SERVICE_NAME:
394-
'cannot connect to database. Service "{service_name}" is not '
395-
'registered with the listener at host "{host}" port {port}. '
396-
'(Similar to ORA-12514)',
396+
'Service "{service_name}" is not registered with the listener at '
397+
'host "{host}" port {port}. (Similar to ORA-12514)',
397398
ERR_INVALID_SID:
398-
'cannot connect to database. SID "{sid}" is not registered '
399-
'with the listener at host "{host}" port {port}. '
400-
'(Similar to ORA-12505)',
399+
'SID "{sid}" is not registered with the listener at host "{host}" '
400+
'port {port}. (Similar to ORA-12505)',
401401
ERR_KEYWORD_ARGS_MUST_BE_DICT:
402402
'"keyword_parameters" argument must be a dict',
403403
ERR_LIBRARY_ALREADY_INITIALIZED:
404404
'init_oracle_client() was already called with different arguments',
405405
ERR_LISTENER_REFUSED_CONNECTION:
406-
'cannot connect to database. Listener refused connection. '
407-
'(Similar to ORA-{error_code})',
406+
'Listener refused connection. (Similar to ORA-{error_code})',
408407
ERR_LOB_OF_WRONG_TYPE:
409408
'LOB is of type {actual_type_name} but must be of type '
410409
'{expected_type_name}',
@@ -488,11 +487,9 @@ def _raise_from_string(exc_type: Exception, message: str) -> None:
488487
ERR_TIME_NOT_SUPPORTED:
489488
'Oracle Database does not support time only variables',
490489
ERR_TNS_ENTRY_NOT_FOUND:
491-
'cannot connect to database. Unable to find "{name}" in '
492-
'{file_name}',
490+
'unable to find "{name}" in {file_name}',
493491
ERR_TNS_NAMES_FILE_MISSING:
494-
'cannot connect to database. File tnsnames.ora not found in '
495-
'{config_dir}',
492+
'file tnsnames.ora not found in {config_dir}',
496493
ERR_UNEXPECTED_DATA:
497494
'unexpected data received: {data}',
498495
ERR_UNEXPECTED_END_OF_DATA:
@@ -517,7 +514,7 @@ def _raise_from_string(exc_type: Exception, message: str) -> None:
517514
'password verifier type 0x{verifier_type:x} is not supported by '
518515
'python-oracledb in thin mode',
519516
ERR_WALLET_FILE_MISSING:
520-
'cannot connect to database. Wallet file {name} was not found',
517+
'wallet file {name} was not found',
521518
ERR_WRONG_ARRAY_DEFINITION:
522519
'expecting a list of two elements [type, numelems]',
523520
ERR_WRONG_EXECUTE_PARAMETERS_TYPE:

src/oracledb/impl/thin/connection.pyx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,13 @@ cdef class ThinConnImpl(BaseConnImpl):
101101
try:
102102
self._protocol._connect_phase_one(self, params, description,
103103
address, connect_string)
104-
except exceptions.DatabaseError:
104+
except (exceptions.DatabaseError, socket.gaierror,
105+
ConnectionRefusedError) as e:
105106
if raise_exception:
106-
raise
107-
return 0
108-
except (socket.gaierror, ConnectionRefusedError) as e:
109-
if raise_exception:
110-
errors._raise_err(errors.ERR_CONNECTION_FAILED, cause=e,
111-
exception=str(e))
107+
errors._raise_err(errors.ERR_CONNECTION_FAILED, cause=e)
112108
return 0
113109
except Exception as e:
114-
errors._raise_err(errors.ERR_CONNECTION_FAILED, cause=e,
115-
exception=str(e))
110+
errors._raise_err(errors.ERR_CONNECTION_FAILED, cause=e)
116111
self._drcp_enabled = description.server_type == "pooled"
117112
if self._cclass is None:
118113
self._cclass = description.cclass

0 commit comments

Comments
 (0)