From 1b4fdf35dd6c21d600130c42a1bcb5c56b25afa6 Mon Sep 17 00:00:00 2001 From: Sam T Date: Tue, 11 Jun 2013 06:00:57 +0400 Subject: ~ Use exception in fromFile. Again, the problem is that one function returns errors in two different ways: Either and IO exceptions. It's better to just throw exception in either case. --- src/Data/Torrent.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/Data/Torrent.hs') diff --git a/src/Data/Torrent.hs b/src/Data/Torrent.hs index 3175e151..068e9cb6 100644 --- a/src/Data/Torrent.hs +++ b/src/Data/Torrent.hs @@ -55,6 +55,8 @@ import Prelude hiding (sum) import Control.Applicative import Control.Arrow +import Control.Exception +import Control.Monad import Data.BEncode as BE import Data.Char import Data.Foldable @@ -353,8 +355,8 @@ isMultiFile MultiFile {} = True isMultiFile _ = False -- | Read and decode a .torrent file. -fromFile :: FilePath -> IO (Result Torrent) -fromFile filepath = decoded <$> B.readFile filepath +fromFile :: FilePath -> IO Torrent +fromFile = B.readFile >=> either (throwIO . userError) return . decoded {----------------------------------------------------------------------- Info hash -- cgit v1.2.3