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

Raise more useful error if mismatch between feature enabled and db url #1124

Open
katrinabrock opened this Issue Aug 20, 2017 · 5 comments

Comments

Projects
None yet
6 participants
@katrinabrock
Contributor

katrinabrock commented Aug 20, 2017

@sgrif

Problem Description

If proper features are not enabled, error messages to not point to this being the issue.

What are you trying to accomplish?

Started project with one backend, switched to a different backend and forgot to change Cargo.toml.

What is the expected output?

If DATABASE_URL is for a database where feature is not enabled, there should at least be a warning about this.

What is the actual output?

help: message: Could not load table names from databasepostgresql://sammy:sam
my@localhost/diesel_demo: StringError("Failed to establish a database connection a t postgresql://sammy:sammy@localhost/diesel_demo. Error: BadConnection(\"Unable to open the database file\")")

Steps to reproduce

Cargo.toml
[dependencies] diesel = { version = "0.15.0", features = ["sqlite"] } diesel_codegen = { version = "0.15.0", features = ["sqlite"] } dotenv = "0.9.0"
.env
DATABASE_URL=postgres://username:password@localhost/diesel_demo > .env

Checklist

  • I have already looked over the issue tracker for similar issues.
@sgrif

This comment has been minimized.

Member

sgrif commented Sep 5, 2017

To clarify, specifically I think we should be checking for the URL starting with mysql://, postgres:// or postgresql:// when those features are not enabled. I think we can safely assume that the user is not trying to connect to a SQLite database in that case.

@sgrif

This comment has been minimized.

Member

sgrif commented Sep 30, 2017

Related: We should strip sqlite:// from the URL if it's present. I've had a couple people try that expecting it to work.

@bbqsrc

This comment has been minimized.

bbqsrc commented Jul 2, 2018

This just broke my mind for a while, as I changed computers and couldn't understand the error that diesel-cli was giving me. Trying to connect to a postgres db with only the sqlite feature enabled provides the following:

$ diesel migration run
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ConnectionError(BadConnection("Unable to open the database file"))', libcore/result.rs:945:5

So yeah, this is still less than ideal. :)

@christiansakai

This comment has been minimized.

christiansakai commented Oct 16, 2018

I literally just encountered this problem and went on for 2 days.... Glad I found this issue.

@AndrewSpeed

This comment has been minimized.

Contributor

AndrewSpeed commented Oct 25, 2018

I'll take a look at implementing this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment