Skip to content

Commit

Permalink
add better error control
Browse files Browse the repository at this point in the history
  • Loading branch information
TTENSHII committed Jan 5, 2024
1 parent 6a6bafb commit 570e147
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
19 changes: 19 additions & 0 deletions lvtrun/app/Errors.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{-
-- EPITECH PROJECT, 2023
-- Leviator Run
-- File description:
-- Errors
-}

module Errors
(
exitWithError
)
where

import System.Exit (exitWith, ExitCode(..))

exitWithError :: String -> IO a
exitWithError msg = do
putStrLn msg
exitWith $ ExitFailure 84
1 change: 0 additions & 1 deletion lvtrun/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
module Main (main) where

import WasmMod.Module
import WasmMod.Header

main :: IO ()
main = do
Expand Down
7 changes: 6 additions & 1 deletion lvtrun/app/WasmMod/Module.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ module WasmMod.Module
where

import qualified Data.ByteString as BS (ByteString, unpack, readFile)
import Control.Monad (when)
import Numeric (showHex)

import WasmMod.Header
import WasmMod.Sections
import Errors

data WasmModule = WasmModule {
header :: ModHeader,
Expand All @@ -37,4 +39,7 @@ getFileContent path = BS.readFile path
loadModule :: String -> IO WasmModule
loadModule filePath = do
bytes <- getFileContent filePath
return $ WasmModule (getModuleHeader bytes) []
let modHeader = getModuleHeader bytes
when (not $ isHeaderValid modHeader) $ exitWithError "Invalid header"
let modSections = []
return $ WasmModule modHeader modSections
1 change: 1 addition & 0 deletions lvtrun/lvtrun.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ library
executable lvtrun-exe
main-is: Main.hs
other-modules:
Errors
WasmMod.Header
WasmMod.Module
WasmMod.Sections
Expand Down

0 comments on commit 570e147

Please sign in to comment.