Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PdoException leakage - API encapsulation breakage #292

Open
jkuchar opened this issue Jun 8, 2018 · 4 comments
Open

PdoException leakage - API encapsulation breakage #292

jkuchar opened this issue Jun 8, 2018 · 4 comments

Comments

@jkuchar
Copy link
Contributor

jkuchar commented Jun 8, 2018

Version: 3.1.1

Bug Description

When I configure dibi to use existing PDO connection which has configured to throw exceptions instead of throwing warnings, encapsulations is broken.

Steps To Reproduce

// pseudocode
$pdoConnection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$dibiConnection = Dibi::connect(["driver"=>"pdo", "connection" => $pdoConnection]);
try {
  $dibiConnection->exec("WHAT EVER WITH ERROR IN IT");
} catch (Dibi\DriverException $e) {
  echo "catched";
} 

output:

Fatal error: unhandled exception ...

Expected Behavior

try {
  $dibiConnection->exec("WHAT EVER WITH ERROR IN IT");
} catch (Dibi\DriverException $e) {
  echo "catched";
} 

output:

catched
exited (0)

Possible Solution

a. Throw exception in dibi::connect() if misconfigured PDO connection is provided.
b. Wrap connection into proxy which reconfigures temporarily connection when used by dibi (can has ugly side effects)
c. Catch exceptions in Dibi code alongside with classic error handling (increases dibi internal code complexity)

I would prefer to go with a) as it fails fast, it is simple to implement and does not have any side effects.

@dg
Copy link
Owner

dg commented Jun 8, 2018

I would prefer to go with a) in 4.0.x & 3.2.x and c) for 4.1.0.

Can you implement it?

@jkuchar
Copy link
Contributor Author

jkuchar commented Jun 11, 2018

Will try to propose something.

@jkuchar
Copy link
Contributor Author

jkuchar commented Jun 11, 2018

I have created two PRs, consider them as drafts, feedback is welcome.

@dg
Copy link
Owner

dg commented Jun 11, 2018

Thanks!

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

No branches or pull requests

2 participants