When diesel_cli can't connect to DB it prints a very cryptic error.
When diesel_cli can't connect to DB it prints a very cryptic error. It's really user-unfriendly to just call unwrap in such a user-facing tool.
Migrate database with wrong credentials supplyed
C:\tmp\lemmy>diesel migration run --database-url postgres://localhost/lemmy
Could not authenticate to database, please supply password.
err value: BadConnection("fe_sendauth: no password supplied\n")
Or something like that. Perhaps even point out to add username:pass@ to the URL
At least it should be something like:
Could not connect to the database. Error is:
ConnectionError(BadConnection("fe_sendauth: no password supplied\n"))
C:\tmp\lemmy>diesel migration run --database-url postgres://localhost/lemmy
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ConnectionError(BadConnection("fe_sendauth: no password supplied\n"))', C:\Users\martb\.cargo\registry\src\github.com-1ecc6299db9ec823\diesel_cli-1.4.1\src/main
.rs:83:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
No
It also fails same way on wrong password, just message is different: (BadConnection("FATAL: password authentication failed for user \"lemmy\"\n")
Changing the concrete error message string is quite hard as they are coming directly from libpq. Otherwise I can see that it may be desirable for diesel_cli to gracefully emit error messages instead of just panicing. So if someone want's to work on this I'm happy to accept patches here, otherwise this is not a priority issue for myself to work on.
I agree that it's not priority one, but nice to have :-)
To add something actionable for someone that wants to work on this: The likely fix is to just improve this function in diesel_cli in such a way that it prints a "nice" error message. Marking this as help wanted as this is open for contributions.
I will working on this.
It seems the issue already fixed.
I got the output look like:
➜ doesel-test ../diesel/target/debug/diesel migration run --database-url postgres://localhost/lemmy
fe_sendauth: no password supplied
@hi-rustin I believe this error message could be improved to include some more information. Something like forming a complete error message that includes some context what exactly failed. So for this example it should emit something like:
Could not connect to database via {DATABASE_URL}: {ERROR_MESSAGE_FROM_LIBPQ}
Most helpful comment
I will working on this.