Skip to content

Improve driver error message#7063

Closed
Arman-Hosseini wants to merge 1 commit intodoctrine:4.3.xfrom
Arman-Hosseini:patch-1
Closed

Improve driver error message#7063
Arman-Hosseini wants to merge 1 commit intodoctrine:4.3.xfrom
Arman-Hosseini:patch-1

Conversation

@Arman-Hosseini
Copy link

Q A
Type improvement
Fixed issues N/A

Summary

While working on a Symfony 7.4 project using PHP 8.3, I encountered the following error when trying to run database migrations on a PostgreSQL database:

In ExceptionConverter.php line 92:

An exception occurred in the driver: could not find driver

At first, the message was unclear and didn't indicate the root cause. It also didn't reference PostgreSQL or the database layer explicitly, which made it harder to debug. After further investigation, I discovered that the pdo_pgsql extension was not installed for PHP 8.3.

To improve clarity and developer experience, I updated the exception.
This wording makes it clearer that the issue is related to the database driver and may help developers diagnose the problem more quickly.

@derrabus
Copy link
Member

derrabus commented Aug 2, 2025

I fail to understand how the proposed change would've helped uncover that the PDO extension was missing.

@greg0ire
Copy link
Member

greg0ire commented Aug 2, 2025

I upvoted the description then felt something similar when seeing the diff.

@Arman-Hosseini
Copy link
Author

My intention was to make the error message more explicit about which component encountered an issue, to help users quickly narrow down the area to investigate. I agree that this change alone does not directly indicate a missing PDO extension, but it may help users distinguish between different types of drivers in larger applications.

@Arman-Hosseini
Copy link
Author

I'd like to propose an enhancement also for the connection logic to provide immediate and actionable feedback when a required PHP extension for the database driver is missing.
DriverManager.php:

if (!extension_loaded($params['driver'])) {
    throw Exception::driverNotInstalled($params['driver']);
}

Exception.php:

public static function driverNotInstalled(string $driverName): self
{
    return new self(sprintf('Please install the "%s" PHP extension.', $driverName, PHP_EOL));
}

@derrabus
Copy link
Member

derrabus commented Aug 4, 2025

My intention was

Your intention is good, but the proposed change does not achieve your goal. I'm sorry, but I'm going to close this PR. If you find a better way, please open a new PR.

@derrabus derrabus closed this Aug 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants