diff options
author | Sam T <pxqr.sta@gmail.com> | 2013-06-11 06:00:57 +0400 |
---|---|---|
committer | Sam T <pxqr.sta@gmail.com> | 2013-06-11 06:00:57 +0400 |
commit | 1b4fdf35dd6c21d600130c42a1bcb5c56b25afa6 (patch) | |
tree | 136bb1467f5d3b5929620ddb0ab2adffc656504d /src/Data | |
parent | a6490c275b6c688df1f654bff92f96aaeb998805 (diff) |
~ 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.
Diffstat (limited to 'src/Data')
-rw-r--r-- | src/Data/Torrent.hs | 6 |
1 files changed, 4 insertions, 2 deletions
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) | |||
55 | 55 | ||
56 | import Control.Applicative | 56 | import Control.Applicative |
57 | import Control.Arrow | 57 | import Control.Arrow |
58 | import Control.Exception | ||
59 | import Control.Monad | ||
58 | import Data.BEncode as BE | 60 | import Data.BEncode as BE |
59 | import Data.Char | 61 | import Data.Char |
60 | import Data.Foldable | 62 | import Data.Foldable |
@@ -353,8 +355,8 @@ isMultiFile MultiFile {} = True | |||
353 | isMultiFile _ = False | 355 | isMultiFile _ = False |
354 | 356 | ||
355 | -- | Read and decode a .torrent file. | 357 | -- | Read and decode a .torrent file. |
356 | fromFile :: FilePath -> IO (Result Torrent) | 358 | fromFile :: FilePath -> IO Torrent |
357 | fromFile filepath = decoded <$> B.readFile filepath | 359 | fromFile = B.readFile >=> either (throwIO . userError) return . decoded |
358 | 360 | ||
359 | {----------------------------------------------------------------------- | 361 | {----------------------------------------------------------------------- |
360 | Info hash | 362 | Info hash |