Diesel: [diesel_cli] Non user friendly error on missing password

Created on 15 Feb 2021  Â·  6Comments  Â·  Source: diesel-rs/diesel

When diesel_cli can't connect to DB it prints a very cryptic error.

Setup

Versions

  • Rust: 1.47.0 (18bf6b4f0 2020-10-07)
  • Diesel: v1.4.1
  • Database: Postgres 13
  • Operating System: Windows 10

Feature Flags

  • diesel: postgres sqlite-bundled

Problem Description

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.

What are you trying to accomplish?

Migrate database with wrong credentials supplyed

What is the expected output?

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"))

What is the actual output?

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

Are you seeing any additional errors?

No

Steps to reproduce

  1. Install diesel_cli
  2. Run migrations in ANY existing project using Postgres instance with wrong credentials supplied (given no peer auth is being used)

It also fails same way on wrong password, just message is different: (BadConnection("FATAL: password authentication failed for user \"lemmy\"\n")

Checklist

  • [X] I have already looked over the issue tracker and the disussion forum for similar possible closed issues.
    (I've searched by text "no password supplied")
  • [x] This issue can be reproduced on Rust's stable channel. (Your issue will be
    closed if this is not the case)
  • [X] This issue can be reproduced without requiring a third party crate
cli enhancement good first issue help wanted

Most helpful comment

I will working on this.

All 6 comments

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}
Was this page helpful?
0 / 5 - 0 ratings