cruncher-types-1.0.2: src/Evalso/Cruncher/FinalResult.hs
{-# LANGUAGE OverloadedStrings, Trustworthy #-}
-- |
-- Maintainer : Ricky Elrod <ricky@elrod.me>
-- Stability : stable
--
-- The highest level of a response that Cruncher deals with. Contains only the
-- final result of a sandbox run, including compilation and execution.
module Evalso.Cruncher.FinalResult (FinalResult (..)) where
import Evalso.Cruncher.SandboxResult
import Control.Applicative
import Control.Monad (mzero)
import Data.Aeson
-- | The final result for a given request.
--
-- This data type also handles error handling, in the form of types.
data FinalResult
= FinalResult
{
compile :: Maybe SandboxResult -- ^ The compilation result, if any
, run :: Maybe SandboxResult -- ^ The execution result, if any
}
| NoSuchLanguage
| SELinuxNotEnforcing
deriving (Eq, Show)
instance ToJSON FinalResult where
toJSON (FinalResult compile' run') = object
[
"compile" .= compile'
, "run" .= run'
]
-- | TODO: i18n
toJSON (NoSuchLanguage) = object ["error" .= noSuchLanguageError]
where
noSuchLanguageError :: String
noSuchLanguageError = "We do not currently support that language"
-- | TODO: i18n
toJSON (SELinuxNotEnforcing) = object ["error" .= selinuxError]
where
selinuxError :: String
selinuxError = "Internal security error - halting request"
instance FromJSON FinalResult where
parseJSON (Object v) = FinalResult <$>
v .: "compile"
<*> v .: "run"
parseJSON _ = mzero