2module Build.Interface (load,decode,isValid) where
4import qualified Data.ByteString.Lazy as L
5import qualified Data.Binary as Binary
7import qualified Elm.Internal.Version as Version
8import System.Directory (doesFileExist)
10import SourceSyntax.Module
12load :: FilePath -> IO (Either String L.ByteString)
14 exists <- doesFileExist filePath
17 byteString <- L.readFile filePath
18 return $ Right byteString
21 return $ Left $ "Unable to find file " ++ filePath ++
22 " for deserialization!"
24decode :: Binary.Binary a => FilePath -> L.ByteString -> Either String a
25decode filePath bytes =
26 case Binary.decodeOrFail bytes of
27 Right (_, _, binaryInfo) -> Right binaryInfo
29 Left (_, offset, err) ->
31 [ "Error reading build artifact: ", filePath, "\n"
32 , " The exact error was '", err, "' at offset ", show offset, ".\n"
33 , " The file was generated by a previous build and may be outdated or corrupt.\n"
34 , " Please remove the file and try again."
37isValid :: FilePath -> (String, ModuleInterface) -> Either String (String, ModuleInterface)
38isValid filePath (name, interface) =
39 if iVersion interface == Version.elmVersion
40 then Right (name, interface)
42 [ "Error reading build artifact: ", filePath, "\n"
43 , " It was generated by a different version of the compiler: "
44 , show (iVersion interface), "\n"
45 , " Please remove the file and try again.\n"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list