knuckleswtf / scribe

Generate API documentation for humans from your Laravel codebase.✍
https://scribe.knuckles.wtf/laravel/
MIT License
1.7k stars 303 forks source link

DatabaseTransactionHelpers swallows PDOException #781

Open dwightwatson opened 9 months ago

dwightwatson commented 9 months ago

Scribe version

4.29.0

PHP version

8.3.0

Framework

Laravel

Framework version

10.39.0

Scribe config

try_it_out.enabled => false
auth.enabled => true
auth.default => true
auth.placeholder => "{API_TOKEN}"

What happened?

I've been trying to build my docs using GitHub actions and running into the exception thrown here. The problem is that this hides the real error and makes every error look like it's a connection issue.

try {
    $driver->beginTransaction();
} catch (PDOException $e) {
    throw new \Exception(
        "Failed to connect to database connection '$connection'." .
        " Is the database running?" .
        " If you aren't using this database, remove it from the `database_connections_to_transact` config array."
    );
}

In this instance I received an exception with the message Failed to connect to the database connection 'pgsql'. However the actual issue was that I hadn't run my database migrations prior to generating the docs.

I wonder if this thrown Exception should include the message from the PDOException, or instead don't catch the PDOException.

Docs

shalvah commented 9 months ago

Yeah, including the actual message should be the right thing.