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

Fluent does not raise error in database connection, when passed with wrong credentials. #706

Open
mauliknshah opened this issue Nov 3, 2020 · 0 comments

Comments

@mauliknshah
Copy link

I'm using the Fluent as a library independently of vapor, and trying to connect to database using the following simple code:

// Assume that the 'databases', 'logger', and 'eventloop' objects are initialized correctly.
// The connectionString has a wrong set of credentials, but forms a valid postgres connection string. 
do  {
            try databases.use(.postgres(url: connectionString), as: .psql)
            database = databases.database(.psql, logger: logger, on: databases.eventLoopGroup.next())
        } catch {
            throw error
        }

Now, in case of correct credentials, the database connects without any issues. On the other hand, if the database credentials are wrong, the databases.use does not throw any error.

For now, I have found a temporary workaround as follows:


do {
            try databases.use(.postgres(url: connectionString), as: .psql)
            database = databases.database(.psql, logger: logger, on: databases.eventLoopGroup.next())
            // Note: Fluent does not throw error with wrong credentials.
            // Temporary workaround.
            guard let postgres = database as? PostgresDatabase else {
                //Throw some error. 
            }
            _ = try postgres.simpleQuery("SELECT 1").wait()
        }
        catch {
            throw error
        }

Could you please correct the fluent API to test connection in the use call, and throw error if the database is not being able to connect?

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

1 participant