From 60d538f76659f343b5fcdbb0ecbec6e157bdba91 Mon Sep 17 00:00:00 2001 From: Andrea Rossato Date: Tue, 24 Jul 2007 14:01:06 +0200 Subject: better error handling in Main.hs darcs-hash:20070724120106-d6583-0a4a02d25dddcf0c005a295db06e4a009851292d.gz --- Main.hs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'Main.hs') diff --git a/Main.hs b/Main.hs index 8ade001..8cf0403 100644 --- a/Main.hs +++ b/Main.hs @@ -51,10 +51,11 @@ main = -- | Reads the configuration files or quits with an error readConfig :: FilePath -> IO Config readConfig f = - do s <- readFile f + do file <- fileExist f + s <- if file then readFile f else error $ f ++ ": file not found!\n" ++ usage case reads s of [(config,_)] -> return config - [] -> error ("Corrupt config file: " ++ f) + [] -> error $ f ++ ": configuration file contains errors!\n" ++ usage _ -> error ("Some problem occured. Aborting...") -- | Read default configuration file or load the default config @@ -108,7 +109,7 @@ getOpts argv = usage :: String usage = (usageInfo header options) ++ footer where header = "Usage: xmobar [OPTION...] [FILE]\nOptions:" - footer = "Mail bug reports and suggestions to " ++ mail + footer = "\nMail bug reports and suggestions to " ++ mail version :: String version = "Xmobar 0.7 (C) 2007 Andrea Rossato " ++ mail ++ license -- cgit v1.2.3