Copyright | Brent Yorgey |
---|---|
License | BSD-3-Clause |
Maintainer | byorgey@gmail.com |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Runtime exceptions for the Swarm language interpreter.
Synopsis
- data Exn
- data IncapableFix
- formatExn :: EntityMap -> Exn -> Text
- formatIncapable :: EntityMap -> IncapableFix -> Requirements -> Term -> Text
- formatIncapableFix :: IncapableFix -> Text
Documentation
The type of exceptions that can be thrown by robot programs.
Fatal Text | Something went very wrong. This is a bug in Swarm and cannot
be caught by a |
InfiniteLoop | An infinite loop was detected via a blackhole. This cannot
be caught by a |
Incapable IncapableFix Requirements Term | A robot tried to do something for which it does not have some
of the required capabilities. This cannot be caught by a
|
CmdFailed Const Text | A command failed in some "normal" way (e.g. a |
User Text | The user program explicitly called |
Instances
data IncapableFix Source #
Suggested way to fix incapable error.
FixByInstall | Install the missing device on yourself/target |
FixByObtain | Add the missing device to your inventory |
Instances
FromJSON IncapableFix Source # | |
Defined in Swarm.Game.Exception parseJSON :: Value -> Parser IncapableFix # parseJSONList :: Value -> Parser [IncapableFix] # | |
ToJSON IncapableFix Source # | |
Defined in Swarm.Game.Exception toJSON :: IncapableFix -> Value # toEncoding :: IncapableFix -> Encoding # toJSONList :: [IncapableFix] -> Value # toEncodingList :: [IncapableFix] -> Encoding # | |
Generic IncapableFix Source # | |
Defined in Swarm.Game.Exception type Rep IncapableFix :: Type -> Type # from :: IncapableFix -> Rep IncapableFix x # to :: Rep IncapableFix x -> IncapableFix # | |
Show IncapableFix Source # | |
Defined in Swarm.Game.Exception showsPrec :: Int -> IncapableFix -> ShowS # show :: IncapableFix -> String # showList :: [IncapableFix] -> ShowS # | |
Eq IncapableFix Source # | |
Defined in Swarm.Game.Exception (==) :: IncapableFix -> IncapableFix -> Bool # (/=) :: IncapableFix -> IncapableFix -> Bool # | |
type Rep IncapableFix Source # | |
formatExn :: EntityMap -> Exn -> Text Source #
Pretty-print an exception for displaying to the player.
Helper functions
formatIncapable :: EntityMap -> IncapableFix -> Requirements -> Term -> Text Source #
Pretty print the incapable exception with an actionable suggestion on how to fix it.
>>>
w = mkEntity (defaultEntityDisplay 'l') "magic wand" [] [] [CAppear]
>>>
r = mkEntity (defaultEntityDisplay 'o') "the one ring" [] [] [CAppear]
>>>
m = buildEntityMap [w,r]
>>>
incapableError cs t = putStr . unpack $ formatIncapable m FixByInstall cs t
>>>
incapableError (R.singletonCap CGod) (TConst As)
Thou shalt not utter such blasphemy: 'as' If God in troth thou wantest to play, try thou a Creative game.
>>>
incapableError (R.singletonCap CAppear) (TConst Appear)
You do not have the devices required for: 'appear' Please install: - the one ring or magic wand
>>>
incapableError (R.singletonCap CRandom) (TConst Random)
Missing the random capability for: 'random' but no device yet provides it. See https://github.com/swarm-game/swarm/issues/26
>>>
incapableError (R.singletonInv 3 "tree") (TConst Noop)
You are missing required inventory for: 'noop' Please obtain: - tree (3)