Add proper Exceptions to class instead of false return on critical problems

This commit is contained in:
Clemens Schwaighofer
2023-09-01 18:32:57 +09:00
parent 8126f08b8c
commit c57e798591
20 changed files with 626 additions and 383 deletions

View File

@@ -340,6 +340,7 @@ class IO
// 4: convert numeric/floatN to float (CONVERT_NUMERIC)
// 8: convert bytea to string data (CONVERT_BYTEA)
/** @var int type settings as bit mask, 0 for off, anything >2 will aways set 1 too */
/** @phan-suppress-next-line PhanInvalidConstantExpression, PhanUndeclaredClassConstant */
private int $convert_type = Convert::off->value;
// FOR BELOW: (This should be private and only readable through some method)
// cursor array for cached readings
@@ -413,6 +414,7 @@ class IO
* phpcs:ignore
* @param array{db_name:string,db_user:string,db_pass:string,db_host:string,db_port:int,db_schema:string,db_encoding:string,db_type:string,db_ssl:string,db_convert_type?:string[]} $db_config DB configuration array
* @param \CoreLibs\Logging\Logging $log Logging class
* @throws \RuntimeException If no DB connection can be established on launch
*/
public function __construct(
array $db_config,
@@ -491,6 +493,7 @@ class IO
if (!$this->__connectToDB()) {
$this->__dbError(16);
$this->db_connection_closed = true;
throw new \RuntimeException('INIT: No DB Handler found / connect or reconnect failed', 16);
}
}
@@ -973,9 +976,9 @@ class IO
/**
* write an error
*
* @param integer $error_id Any Error ID, used in debug message string
* @param integer $error_id Any Error ID, used in debug message string
* @param \PgSql\Result|false $cursor Optional cursor, passed on to preprocessor
* @param string $msg optional message added to debug
* @param string $msg optional message added to debug
* @return void
*/
protected function __dbError(