1module InterfaceSerialization ( loadInterface
6import qualified Data.ByteString.Lazy as L
7import qualified Data.Binary as Binary
9import qualified Elm.Internal.Version as Version
10import System.Directory (doesFileExist)
11import System.IO (hPutStrLn, stderr)
12import System.Exit (exitFailure)
14import SourceSyntax.Module
16loadInterface :: FilePath -> IO (Either String L.ByteString)
17loadInterface filePath = do
18 exists <- doesFileExist filePath
21 byteString <- L.readFile filePath
22 return $ Right byteString
25 return $ Left $ "Unable to find file " ++ filePath ++
26 " for deserialization!"
28interfaceDecode :: Binary.Binary a =>
29 FilePath -> L.ByteString -> Either String a
30interfaceDecode filePath bytes = do
31 case Binary.decodeOrFail bytes of
32 Right (_, _, binaryInfo) -> Right binaryInfo
34 Left (_, offset, err) ->
35 Left $ concat [ "Error reading build artifact: ", filePath, "\n"
36 , " The exact error was '", err, "' at offset ", show offset, ".\n"
37 , " The file was generated by a previous build and may be outdated or corrupt.\n"
38 , " Please remove the file and try again."
41validVersion :: FilePath -> (String, ModuleInterface) ->
42 Either String (String, ModuleInterface)
43validVersion filePath (name, interface) =
44 if iVersion interface == Version.elmVersion then
45 Right (name, interface)
48 [ "Error reading build artifact: ", filePath, "\n"
49 , " It was generated by a different version of the compiler: "
50 , show (iVersion interface), "\n"
51 , " 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