From a243beab2c26f224066720ccd630a9eb9b2278f1 Mon Sep 17 00:00:00 2001 From: Erik de Castro Lopo Date: Thu, 19 Mar 2020 08:45:34 +1100 Subject: [PATCH] Better error message for readPGPassFile failures --- cardano-db/src/Cardano/Db/PGConfig.hs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cardano-db/src/Cardano/Db/PGConfig.hs b/cardano-db/src/Cardano/Db/PGConfig.hs index 6a56bdd77..e87bf30ad 100644 --- a/cardano-db/src/Cardano/Db/PGConfig.hs +++ b/cardano-db/src/Cardano/Db/PGConfig.hs @@ -1,4 +1,5 @@ {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE ScopedTypeVariables #-} module Cardano.Db.PGConfig ( PGConfig (..) @@ -79,8 +80,12 @@ readPGPassFile (PGPassFile fpath) = do replaceUser pgc | pgcUser pgc /= "*" = pure pgc | otherwise = do - user <- getEffectiveUserName - pure $ pgc { pgcUser = BS.pack user } + euser <- Exception.try getEffectiveUserName + case euser of + Left (_ :: IOException) -> + error "readPGPassFile: User in pgpass file was specified as '*' but getEffectiveUserName failed." + Right user -> + pure $ pgc { pgcUser = BS.pack user } -- | Read 'PGPassFile' into 'PGConfig'.