Skip to content

Commit 88b406b

Browse files
authored
Change dhall freeze to support refreezing imports (#637)
Fixes: #630 `dhall freeze` will now refreeze existing imports if they have a bad semantic integrity check
1 parent fcfae0c commit 88b406b

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/Dhall/Freeze.hs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module Dhall.Freeze
88
, hashImport
99
) where
1010

11+
import Control.Exception (SomeException)
1112
import Data.Monoid ((<>))
1213
import Data.Maybe (fromMaybe)
1314
import Data.Text
@@ -16,6 +17,7 @@ import Dhall.Core (Expr(..), Import(..), ImportHashed(..))
1617
import Dhall.Import (standardVersion)
1718
import Dhall.Parser (exprAndHeaderFromText, Src)
1819
import Dhall.Pretty (annToAnsiStyle, layoutOpts)
20+
import Dhall.TypeCheck (X)
1921
import Lens.Family (set)
2022
import System.Console.ANSI (hSupportsANSI)
2123

@@ -38,9 +40,24 @@ hashImport
3840
-> Import
3941
-> IO Import
4042
hashImport directory _standardVersion import_ = do
43+
let unprotectedImport =
44+
import_
45+
{ importHashed =
46+
(importHashed import_)
47+
{ hash = Nothing
48+
}
49+
}
4150
let status = set standardVersion _standardVersion (Dhall.Import.emptyStatus directory)
4251

43-
expression <- State.evalStateT (Dhall.Import.loadWith (Embed import_)) status
52+
let download =
53+
State.evalStateT (Dhall.Import.loadWith (Embed import_)) status
54+
55+
-- Try again without the semantic integrity check if decoding fails
56+
let handler :: SomeException -> IO (Expr Src X)
57+
handler _ = do
58+
State.evalStateT (Dhall.Import.loadWith (Embed unprotectedImport)) status
59+
60+
expression <- Control.Exception.handle handler download
4461

4562
case Dhall.TypeCheck.typeOf expression of
4663
Left exception -> Control.Exception.throwIO exception

0 commit comments

Comments
 (0)