aboutsummaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorpacien2019-12-29 09:31:38 +0100
committerpacien2019-12-29 09:31:38 +0100
commit1872dbe68d4a68f43990f8a93e3ff4716eecf525 (patch)
tree91068f44a0c27a4c9064e60c94265b9481c8670a /compiler
parent8a5d1600746bbe878b9ff1c4e9a70c7d5bdb3e95 (diff)
downloadldgallery-1872dbe68d4a68f43990f8a93e3ff4716eecf525.tar.gz
compiler: make processing error message mention the problematic file
Diffstat (limited to 'compiler')
-rw-r--r--compiler/src/Processors.hs22
1 files changed, 11 insertions, 11 deletions
diff --git a/compiler/src/Processors.hs b/compiler/src/Processors.hs
index 7bf1e36..67f8619 100644
--- a/compiler/src/Processors.hs
+++ b/compiler/src/Processors.hs
@@ -32,7 +32,7 @@ module Processors
32 ) where 32 ) where
33 33
34 34
35import Control.Exception (throwIO) 35import Control.Exception (Exception, throwIO)
36import Data.Function ((&)) 36import Data.Function ((&))
37import Data.Ratio ((%)) 37import Data.Ratio ((%))
38import Data.Char (toLower) 38import Data.Char (toLower)
@@ -51,6 +51,9 @@ import Resource
51import Files 51import Files
52 52
53 53
54data ProcessingException = ProcessingException FilePath String deriving Show
55instance Exception ProcessingException
56
54data Format = 57data Format =
55 Bmp | Jpg | Png | Tiff | Hdr -- static images 58 Bmp | Jpg | Png | Tiff | Hdr -- static images
56 | Gif -- TODO: might be animated 59 | Gif -- TODO: might be animated
@@ -82,14 +85,6 @@ copyFileProcessor inputPath outputPath =
82 (putStrLn $ "Copying:\t" ++ outputPath) 85 (putStrLn $ "Copying:\t" ++ outputPath)
83 >> ensureParentDir (flip System.Directory.copyFile) outputPath inputPath 86 >> ensureParentDir (flip System.Directory.copyFile) outputPath inputPath
84 87
85eitherIOToIO :: Either String (IO a) -> IO a
86eitherIOToIO (Left err) = throwIO $ userError err
87eitherIOToIO (Right res) = res
88
89eitherResToIO :: Either String a -> IO a
90eitherResToIO (Left err) = throwIO $ userError err
91eitherResToIO (Right res) = return res
92
93resizeStaticImageUpTo :: Format -> Resolution -> FileProcessor 88resizeStaticImageUpTo :: Format -> Resolution -> FileProcessor
94resizeStaticImageUpTo Bmp = resizeStaticGeneric readBitmap saveBmpImage 89resizeStaticImageUpTo Bmp = resizeStaticGeneric readBitmap saveBmpImage
95-- TODO: parameterise export quality for jpg 90-- TODO: parameterise export quality for jpg
@@ -97,7 +92,12 @@ resizeStaticImageUpTo Jpg = resizeStaticGeneric readJpeg (saveJpgImage 80)
97resizeStaticImageUpTo Png = resizeStaticGeneric readPng savePngImage 92resizeStaticImageUpTo Png = resizeStaticGeneric readPng savePngImage
98resizeStaticImageUpTo Tiff = resizeStaticGeneric readTiff saveTiffImage 93resizeStaticImageUpTo Tiff = resizeStaticGeneric readTiff saveTiffImage
99resizeStaticImageUpTo Hdr = resizeStaticGeneric readHDR saveRadianceImage 94resizeStaticImageUpTo Hdr = resizeStaticGeneric readHDR saveRadianceImage
100resizeStaticImageUpTo Gif = resizeStaticGeneric readGif ((.) eitherIOToIO . saveGifImage) 95resizeStaticImageUpTo Gif = resizeStaticGeneric readGif writeGifImage
96 where
97 writeGifImage :: StaticImageWriter
98 writeGifImage outputPath image =
99 saveGifImage outputPath image
100 & either (throwIO . ProcessingException outputPath) id
101 101
102 102
103type StaticImageReader = FilePath -> IO (Either String DynamicImage) 103type StaticImageReader = FilePath -> IO (Either String DynamicImage)
@@ -107,7 +107,7 @@ resizeStaticGeneric :: StaticImageReader -> StaticImageWriter -> Resolution -> F
107resizeStaticGeneric reader writer maxRes inputPath outputPath = 107resizeStaticGeneric reader writer maxRes inputPath outputPath =
108 (putStrLn $ "Generating:\t" ++ outputPath) 108 (putStrLn $ "Generating:\t" ++ outputPath)
109 >> reader inputPath 109 >> reader inputPath
110 >>= eitherResToIO 110 >>= either (throwIO . ProcessingException inputPath) return
111 >>= return . (fitDynamicImage maxRes) 111 >>= return . (fitDynamicImage maxRes)
112 >>= ensureParentDir writer outputPath 112 >>= ensureParentDir writer outputPath
113 113