git.iko.soy/typeable/hjsonschema
on master help sign in
Improve failure names.
commitf06bcf19cbe9e1c29400e49ea3540380bfe6550a authorIan Grant Jeffries <ian@housejeffries.com> dateMon 2 May 2016, 16:57 (10 years ago) parent95f4773
3 files changed+15−15
src/Data/JsonSchema/Draft4.hs+7−7 src/Data/JsonSchema/Fetch.hs+6−6 tests/Local/Filesystem.hs+2−2
src/Data/JsonSchema/Draft4.hs+7−7
@@ -49,9 +49,9 @@ import Data.JsonSchema.Fetch (FilesystemFailure(..),
4949import qualified Data.JsonSchema.Fetch as FE
5050
5151data HTTPValidationFailure
52− = HVRequest HTTPFailure
53− | HVSchema (NonEmpty Failure)
54− | HVData (NonEmpty Failure)
52+ = HVRequest HTTPFailure
53+ | HVSchema (NonEmpty Failure)
54+ | HVData (NonEmpty Failure)
5555 deriving Show
5656
5757fetchHTTPAndValidate
@@ -72,9 +72,9 @@ fetchHTTPAndValidate sw v = do
7272 Just failures -> Left (HVData failures)
7373
7474data FilesystemValidationFailure
75− = FVFilesystem FilesystemFailure
76− | FVSchema (NonEmpty Failure)
77− | FVData (NonEmpty Failure)
75+ = FVRead FilesystemFailure
76+ | FVSchema (NonEmpty Failure)
77+ | FVData (NonEmpty Failure)
7878 deriving Show
7979
8080fetchFilesystemAndValidate
@@ -83,7 +83,7 @@ fetchFilesystemAndValidate
8383 -> IO (Either FilesystemValidationFailure ())
8484fetchFilesystemAndValidate sw v = do
8585 res <- referencesViaFilesystem sw
86− pure (g =<< f =<< left FVFilesystem res)
86+ pure (g =<< f =<< left FVRead res)
8787 where
8888 f :: ReferencedSchemas Schema
8989 -> Either FilesystemValidationFailure (Value -> [Failure])
src/Data/JsonSchema/Fetch.hs+6−6
@@ -54,8 +54,8 @@ data ReferencedSchemas schema = ReferencedSchemas
5454--------------------------------------------------
5555
5656data HTTPFailure
57− = HTTPParseFailure Text
58− | RequestFailure HttpException
57+ = HTTPParseFailure Text
58+ | HTTPRequestFailure HttpException
5959 deriving Show
6060
6161-- | Take a schema. Retrieve every document either it or its subschemas
@@ -78,7 +78,7 @@ referencesViaHTTP' spec sw = do
7878 handler
7979 :: HttpException
8080 -> IO (Either HTTPFailure (ReferencedSchemas schema))
81− handler = pure . Left . RequestFailure
81+ handler = pure . Left . HTTPRequestFailure
8282
8383--------------------------------------------------
8484-- * Fetch via Filesystem
@@ -86,7 +86,7 @@ referencesViaHTTP' spec sw = do
8686
8787data FilesystemFailure
8888 = FSParseFailure Text
89− | ReadFailure IOError
89+ | FSReadFailure IOError
9090 deriving Show
9191
9292referencesViaFilesystem'
@@ -100,12 +100,12 @@ referencesViaFilesystem' spec sw = catch (left FSParseFailure <$> f) handler
100100 f = referencesMethodAgnostic readFile' spec sw
101101
102102 readFile' :: Text -> IO LBS.ByteString
103− readFile' = fmap LBS.fromStrict . (BS.readFile . T.unpack)
103+ readFile' = fmap LBS.fromStrict . BS.readFile . T.unpack
104104
105105 handler
106106 :: IOError
107107 -> IO (Either FilesystemFailure (ReferencedSchemas schema))
108− handler = pure . Left . ReadFailure
108+ handler = pure . Left . FSReadFailure
109109
110110--------------------------------------------------
111111-- * Method Agnostic Fetching Tools
tests/Local/Filesystem.hs+2−2
@@ -27,8 +27,8 @@ readFileExceptions :: IO ()
2727readFileExceptions = do
2828 res <- referencesViaFilesystem (SchemaWithURI schema Nothing)
2929 case res of
30− Left (ReadFailure _) -> pure ()
31− a -> error (msg <> show a)
30+ Left (FSReadFailure _) -> pure ()
31+ a -> error (msg <> show a)
3232 where
3333 schema :: Schema
3434 schema = emptySchema { _schemaRef = Just "does-not-exist.json" }