Skip to content

Commit f4ef5c5

Browse files
jyn514Joshua Nelson
authored and
Joshua Nelson
committed
Give a better error message if database url isn't set
1 parent c0401b1 commit f4ef5c5

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/db/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub use self::delete_crate::delete_crate;
77
pub use self::file::{add_path_into_database, move_to_s3};
88
pub use self::migrate::migrate;
99

10+
use failure::Fail;
1011
use postgres::error::Error;
1112
use postgres::{Connection, TlsMode};
1213
use std::env;
@@ -19,8 +20,8 @@ mod migrate;
1920

2021
/// Connects to database
2122
pub fn connect_db() -> Result<Connection, failure::Error> {
22-
// FIXME: unwrap might not be the best here
23-
let db_url = env::var("CRATESFYI_DATABASE_URL")?;
23+
let err = "CRATESFYI_DATABASE_URL environment variable is not set";
24+
let db_url = env::var("CRATESFYI_DATABASE_URL").map_err(|e| e.context(err))?;
2425
Connection::connect(&db_url[..], TlsMode::None).map_err(Into::into)
2526
}
2627

0 commit comments

Comments
 (0)