- Add DISCOVERY_LOG_LEVEL=debug - Add DISCOVERY_SHOW_PROGRESS=true - Temporary changes for debugging InitializerProcessor fixes on production
147 lines
4.4 KiB
PHP
147 lines
4.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Framework\Exception;
|
|
|
|
/**
|
|
* Database-spezifische Exception mit vorgefertigten Error Codes
|
|
*/
|
|
class DatabaseException extends FrameworkException
|
|
{
|
|
// === Factory Methods für häufige Database Errors ===
|
|
|
|
public static function connectionFailed(
|
|
?string $details = null,
|
|
?\Throwable $previous = null
|
|
): static {
|
|
$context = ExceptionContext::forOperation('database.connect', 'Database')
|
|
->withData(['details' => $details]);
|
|
|
|
$message = $details ? "Database connection failed: $details" : null;
|
|
|
|
return static::create(
|
|
ErrorCode::DB_CONNECTION_FAILED,
|
|
$message,
|
|
$context,
|
|
$previous
|
|
);
|
|
}
|
|
|
|
public static function queryFailed(
|
|
string $sql,
|
|
?string $error = null,
|
|
?\Throwable $previous = null
|
|
): static {
|
|
$context = ExceptionContext::forOperation('database.query', 'Database')
|
|
->withData(['sql' => $sql, 'error' => $error])
|
|
->withDebug(['query_length' => strlen($sql)]);
|
|
|
|
return static::create(
|
|
ErrorCode::DB_QUERY_FAILED,
|
|
"Query execution failed: $error",
|
|
$context,
|
|
$previous
|
|
);
|
|
}
|
|
|
|
public static function constraintViolation(
|
|
string $constraint,
|
|
?string $table = null,
|
|
?array $data = null,
|
|
?\Throwable $previous = null
|
|
): static {
|
|
$context = ExceptionContext::forOperation('database.constraint', 'Database')
|
|
->withData([
|
|
'constraint' => $constraint,
|
|
'table' => $table,
|
|
'violation_data' => $data,
|
|
]);
|
|
|
|
return static::create(
|
|
ErrorCode::DB_CONSTRAINT_VIOLATION,
|
|
"Database constraint violation: $constraint" . ($table ? " on table $table" : ''),
|
|
$context,
|
|
$previous
|
|
);
|
|
}
|
|
|
|
public static function transactionFailed(
|
|
?string $details = null,
|
|
?array $operations = null,
|
|
?\Throwable $previous = null
|
|
): static {
|
|
$context = ExceptionContext::forOperation('database.transaction', 'Database')
|
|
->withData(['details' => $details, 'operations' => $operations]);
|
|
|
|
return static::create(
|
|
ErrorCode::DB_TRANSACTION_FAILED,
|
|
"Transaction failed: $details",
|
|
$context,
|
|
$previous
|
|
);
|
|
}
|
|
|
|
public static function poolExhausted(
|
|
int $maxConnections,
|
|
int $currentConnections,
|
|
?\Throwable $previous = null
|
|
): static {
|
|
$context = ExceptionContext::forOperation('database.pool', 'Database')
|
|
->withData([
|
|
'max_connections' => $maxConnections,
|
|
'current_connections' => $currentConnections,
|
|
'usage_percentage' => round(($currentConnections / $maxConnections) * 100, 2),
|
|
]);
|
|
|
|
return static::create(
|
|
ErrorCode::DB_POOL_EXHAUSTED,
|
|
"Connection pool exhausted ($currentConnections/$maxConnections)",
|
|
$context,
|
|
$previous
|
|
);
|
|
}
|
|
|
|
public static function timeout(
|
|
float $timeoutSeconds,
|
|
string $operation = 'query',
|
|
?string $details = null,
|
|
?\Throwable $previous = null
|
|
): static {
|
|
$context = ExceptionContext::forOperation("database.$operation", 'Database')
|
|
->withData([
|
|
'timeout_seconds' => $timeoutSeconds,
|
|
'operation' => $operation,
|
|
'details' => $details,
|
|
]);
|
|
|
|
return static::create(
|
|
ErrorCode::DB_TIMEOUT,
|
|
"Database operation '$operation' timed out after {$timeoutSeconds}s",
|
|
$context,
|
|
$previous
|
|
);
|
|
}
|
|
|
|
public static function migrationFailed(
|
|
string $migrationName,
|
|
?string $error = null,
|
|
?string $version = null,
|
|
?\Throwable $previous = null
|
|
): static {
|
|
$context = ExceptionContext::forOperation('database.migration', 'Database')
|
|
->withData([
|
|
'migration' => $migrationName,
|
|
'version' => $version,
|
|
'error' => $error,
|
|
]);
|
|
|
|
return static::create(
|
|
ErrorCode::DB_MIGRATION_FAILED,
|
|
"Migration '$migrationName' failed: $error",
|
|
$context,
|
|
$previous
|
|
);
|
|
}
|
|
}
|