@@ -1,6 +1,13 @@
1{-# LANGUAGE RankNTypes #-}
2{-# LANGUAGE RankNTypes #-}
2module Data.Yaml.Include (decodeFile, decodeFileEither) where
3module Data.Yaml.Include (decodeFile, decodeFileEither) where
5+#if !MIN_VERSION_directory(1, 2, 3)
6+import Control.Exception (handleJust)
7+import Control.Monad (guard)
8+import System.IO.Error (ioeGetFileName, ioeGetLocation, isDoesNotExistError)
4import Control.Exception (throwIO)
11import Control.Exception (throwIO)
5import Control.Monad (when)
12import Control.Monad (when)
6import Control.Monad.IO.Class (liftIO)
13import Control.Monad.IO.Class (liftIO)
@@ -25,7 +32,7 @@ eventsFromFile = go []
26 go :: MonadResource m => [FilePath] -> FilePath -> Producer m Event
33 go :: MonadResource m => [FilePath] -> FilePath -> Producer m Event
27 go seen fp = do
34 go seen fp = do
28− cfp <- liftIO $ canonicalizePath fp
35+ cfp <- liftIO $ handleNotFound $ canonicalizePath fp
29 when (cfp `elem` seen) $ do
36 when (cfp `elem` seen) $ do
30 liftIO $ throwIO CyclicIncludes
37 liftIO $ throwIO CyclicIncludes
31 Y.decodeFile cfp $= do
38 Y.decodeFile cfp $= do
@@ -37,6 +44,17 @@ eventsFromFile = go []
38 irrelevantEvents = [EventStreamStart, EventDocumentStart, EventDocumentEnd, EventStreamEnd]
45 irrelevantEvents = [EventStreamStart, EventDocumentStart, EventDocumentEnd, EventStreamEnd]
47+#if !MIN_VERSION_directory(1, 2, 3)
48+ handleNotFound = handleJust
50+ guard (isDoesNotExistError e)
51+ guard (ioeGetLocation e == "canonicalizePath")
53+ (throwIO . YamlException . ("Yaml file not found: " ++))
40-- | Like `Data.Yaml.decodeFile` but with support for relative and absolute
58-- | Like `Data.Yaml.decodeFile` but with support for relative and absolute
41-- includes.
59-- includes.