Skip to content

Commit

Permalink
fix: instead of failing, log warning and use fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
ulidtko committed Nov 3, 2023
1 parent 2f89797 commit 5af68c7
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/Keter/Proxy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ import Network.Wai.Middleware.Gzip (def)
import Data.Monoid (mappend, mempty)
import Data.Proxy
import Data.Tagged
import Data.Text (pack)
import Data.Text as T (pack, unwords)
import Data.Text.Encoding (decodeUtf8With, encodeUtf8)
import Data.Text.Encoding.Error (lenientDecode)
import qualified Data.Vector as V
import GHC.Exts (fromString)
import GHC.TypeLits (KnownSymbol, symbolVal)
import Keter.Config
import Keter.Config.Middleware
Expand Down Expand Up @@ -117,14 +118,16 @@ makeSettings hostman = do

taggedReadFile :: forall r key. KnownSymbol key
=> Tagged key (Maybe FilePath) -> r -> (ByteString -> r) -> KeterM KeterConfig r
taggedReadFile (Tagged Nothing) fallback _ = pure fallback
taggedReadFile (Tagged (Just file)) _ processContents = do
taggedReadFile (Tagged Nothing) fallback _ = pure fallback
taggedReadFile (Tagged (Just file)) fallback processContents = do
isExist <- liftIO $ Dir.doesFileExist file
if isExist then liftIO (S.readFile file) <&> processContents else do
wd <- liftIO Dir.getCurrentDirectory
error $ "could not find " <> tag <> " on path '" <> file <> "' with working dir '" <> wd <> "'"
-- FIXME instead of failing, log a warning and return fallback value?
where tag = symbolVal (Proxy :: Proxy key)
logWarnN . T.unwords $ ["could not find", tag, "on path", quote file, "with working dir", quote wd]
return fallback
where
tag = fromString $ symbolVal (Proxy :: Proxy key)
quote = ("'" <>) . (<> "'") . fromString

reverseProxy :: ListeningPort -> KeterM ProxySettings ()
reverseProxy listener = do
Expand Down

0 comments on commit 5af68c7

Please sign in to comment.