gdritter repos telml / 41da192
start to do better error-handling Getty Ritter 1 year, 11 months ago
1 changed file(s) with 29 addition(s) and 12 deletion(s). Collapse all Expand all
145145 [ "Lua definition of `telml.",
146146 Text.unpack (nafName naf),
147147 "` not a function, found ",
148 go (nafActual naf),
148 ppType (nafActual naf),
149149 " instead"
150150 ]
151151 where
152 go Lua.TypeNil = "nil"
153 go Lua.TypeBoolean = "boolean"
154 go Lua.TypeLightUserdata = "userdata (light)"
155 go Lua.TypeNumber = "number"
156 go Lua.TypeString = "string"
157 go Lua.TypeTable = "table"
158 go Lua.TypeFunction = "function"
159 go Lua.TypeUserdata = "userdata"
160 go Lua.TypeThread = "thread"
161 go Lua.TypeNone = "something unspeakable"
152
153 data NotAString = NotAString
154 {nasName :: Text.Text, nasActual :: Lua.Type}
155 deriving (Show)
156
157 instance Exn.Exception NotAString where
158 displayException nas =
159 concat
160 [ "Result of calling `telml.",
161 Text.unpack (nasName nas),
162 "` not a string, found ",
163 ppType (nasActual nas),
164 " instead"
165 ]
166 where
167
168 ppType :: Lua.Type -> String
169 ppType Lua.TypeNil = "nil"
170 ppType Lua.TypeBoolean = "boolean"
171 ppType Lua.TypeLightUserdata = "userdata (light)"
172 ppType Lua.TypeNumber = "number"
173 ppType Lua.TypeString = "string"
174 ppType Lua.TypeTable = "table"
175 ppType Lua.TypeFunction = "function"
176 ppType Lua.TypeUserdata = "userdata"
177 ppType Lua.TypeThread = "thread"
178 ppType Lua.TypeNone = "something unspeakable"
162179
163180 standardTags :: Text.Text -> [Text.Text] -> LuaM Text.Text
164181 standardTags n ps =
195212 case result of
196213 Nothing -> do
197214 actualtyp <- Lua.ltype 2
198 error ("expected string, got" ++ show actualtyp)
215 throw (NotAString n actualtyp)
199216 Just r -> do
200217 return (Text.decodeUtf8 r)
201218 _ -> throw (NotAFunction n typ)