From 3a33bda81f0c1694d8726167b20f9386b89096a8 Mon Sep 17 00:00:00 2001 From: Ali Abrar Date: Mon, 23 May 2022 18:13:12 -0400 Subject: [PATCH] assets: report an error in ob run when referenced file doesn't exist --- ChangeLog.md | 1 + lib/asset/manifest/src/Obelisk/Asset/TH.hs | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index 1ed9a72df..ef27d11e4 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -21,6 +21,7 @@ This project's release branch is `master`. This log is written from the perspect * [#903](https://github.com/obsidiansystems/obelisk/pull/903): Added support for a file which allows users to specify global variables and namespaces in JS, that should not be used by the Google Closure Compiler during minification of the GHCJS produced JS. See the [FAQ](FAQ.md). * Static Assets * [#922](https://github.com/obsidiansystems/obelisk/pull/922): Serve .wasm files with the correct MIME type + * Add a warning to ob run when `static` is called with a path to a file that doesn't exist ## v1.0.0.0 - 2022-01-04 diff --git a/lib/asset/manifest/src/Obelisk/Asset/TH.hs b/lib/asset/manifest/src/Obelisk/Asset/TH.hs index efb47c10d..1fd585ffa 100644 --- a/lib/asset/manifest/src/Obelisk/Asset/TH.hs +++ b/lib/asset/manifest/src/Obelisk/Asset/TH.hs @@ -12,8 +12,10 @@ module Obelisk.Asset.TH import Obelisk.Asset.Gather +import Control.Monad import Language.Haskell.TH import Language.Haskell.TH.Syntax +import System.Directory import System.FilePath.Posix -- | Produces the hashed path of a file @@ -31,7 +33,11 @@ staticPrefix :: FilePath staticPrefix = "/static" staticAssetRaw :: FilePath -> Q Exp -staticAssetRaw fp = returnQ $ LitE $ StringL $ staticPrefix fp +staticAssetRaw fp = do + exists <- runIO $ doesFileExist $ "static.out/" <> fp + when (not exists) $ + fail $ "The file " <> fp <> " was not found in static.out" + returnQ $ LitE $ StringL $ staticPrefix fp staticAssetHashed :: FilePath -> FilePath -> Q Exp staticAssetHashed root fp = do