[GH-ISSUE #1017] Raise exceptions on error #542

Closed
opened 2026-02-25 21:35:19 +03:00 by kerem · 0 comments
Owner

Originally created by @jonocodes on GitHub (May 10, 2024).
Original GitHub issue: https://github.com/cypht-org/cypht/issues/1017

Originally assigned to: @josaphatim on GitHub.

🗣 Suggestion

This conversation started here: https://github.com/cypht-org/cypht/issues/977#issuecomment-2098904257

Concerning PDO error modes php.watch/versions/8.0/PDO-default-errmode.

It appears php 7.x defaulted to make them silent, but 8.x is making them throw exceptions. This would have very different behaviors in the way cypht uses them since it is not explicitly setting a mode. So I recommend setting it explicitly.

That being said, I agree with the decision to have it default to throw exceptions. I came upon this when trying to figure out why some database operations were not working while I was developing. cypht seems to capture and hide the actual errors as you can see here:
github.com/cypht-org/cypht@2cf7a0ae88/scripts/create_account.php (L43-L50)

Unless there is another way to expose these errors (perhaps via a debug mode log) you cant see what the issue is, which is needed in order to fix it.

In my testing I was able to turn the above into a single line:

	$auth->create($user, $pass);

I explicitly ask for exceptions to happen when setting up the connection:

self::$dbh[$key]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

That way the (error) logs are actionable.

Originally created by @jonocodes on GitHub (May 10, 2024). Original GitHub issue: https://github.com/cypht-org/cypht/issues/1017 Originally assigned to: @josaphatim on GitHub. ## 🗣 Suggestion This conversation started here: https://github.com/cypht-org/cypht/issues/977#issuecomment-2098904257 Concerning PDO error modes [php.watch/versions/8.0/PDO-default-errmode](https://php.watch/versions/8.0/PDO-default-errmode). It appears php 7.x defaulted to make them silent, but 8.x is making them throw exceptions. This would have very different behaviors in the way cypht uses them since it is not explicitly setting a mode. So I recommend setting it explicitly. That being said, I agree with the decision to have it default to throw exceptions. I came upon this when trying to figure out why some database operations were not working while I was developing. cypht seems to capture and hide the actual errors as you can see here: https://github.com/cypht-org/cypht/blob/2cf7a0ae88215e9ebc10935a0910290cec17fc5d/scripts/create_account.php#L43-L50 Unless there is another way to expose these errors (perhaps via a debug mode log) you cant see what the issue is, which is needed in order to fix it. In my testing I was able to turn the above into a single line: ```php $auth->create($user, $pass); ``` I explicitly ask for exceptions to happen when setting up the connection: ```php self::$dbh[$key]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); ``` That way the (error) logs are actionable.
kerem closed this issue 2026-02-25 21:35:19 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/cypht#542
No description provided.