From 3891f80bf570ddf2882d580de54f66e3af5454bb Mon Sep 17 00:00:00 2001 From: Michael Peyton Jones Date: Thu, 23 May 2019 19:00:35 +0100 Subject: [PATCH] Abort more gracefully if the source files don't exist Fixes #59. --- app/Niv.hs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/Niv.hs b/app/Niv.hs index 7b155c0..0959349 100644 --- a/app/Niv.hs +++ b/app/Niv.hs @@ -58,6 +58,9 @@ newtype Sources = Sources getSources :: IO Sources getSources = do + exists <- Dir.doesFileExist pathNixSourcesJson + unless exists abortSourcesDoesntExist + warnIfOutdated -- TODO: if doesn't exist: run niv init putStrLn $ "Reading sources file" @@ -696,6 +699,14 @@ Make sure the repository exists. -- Abort ------------------------------------------------------------------------------- +abortSourcesDoesntExist :: IO a +abortSourcesDoesntExist = abort $ unlines [ line1, line2 ] + where + line1 = "Cannot use " <> pathNixSourcesJson + line2 = [s| +The sources file does not exist! You may need to run 'niv init'. +|] + abortSourcesIsntAMap :: IO a abortSourcesIsntAMap = abort $ unlines [ line1, line2 ] where