modulePlat.Rendering.Errors(ContextType(..),RenderErr(..),renderErr)whereimportqualifiedData.ByteString.UTF8asBimportData.ListimportPlat.ContextimportPlat.Utils-- | This is an auxiliary type, which indicates what is the type we expected,-- or what is the actual type we've got.dataContextType=CtxString|CtxBool|CtxRecord|CtxArrayinstanceShowContextTypewhereshowCtxString="string"showCtxBool="boolean"showCtxRecord="record"showCtxArray="array"-- | This type represents a rendering error. Note that we provide a 'renderErr' function-- which can be used if you want to present an error to the user.---- This type internals are exposed for you to pattern-match on them, although they can-- change in the future versions.dataRenderErr=ErrorTypeContextTypeContextTypePos[B.ByteString]|-- ^ The expression evaluates to something of the wrong type.-- -- Here, first type is the actual one, while the second is the expected one.ErrorFieldContextTypePos[B.ByteString]|-- ^ The expression can't be evaluated, since there is no field with the given name-- in the record.ErrorOption(Pos,Pos)[RenderErr]|-- ^ There are several options in the template, but all of them failed for some reason.---- Error messages for all options are listed here.ErrorCheckPos[B.ByteString]-- ^ Template asks to check for some boolean expression, which happened to be false.showBS::[B.ByteString]->StringshowBSbs=concat$intersperse"."$mapB.toStringbsinstanceShowRenderErrwhereshow(ErrorTypec1c2pbs)=showp++": "++showBSbs++" - "++showc1++" instead of "++showc2show(ErrorFieldcpbs)=showp++": "++showBSbs++" - no field in a "++showcshow(ErrorOption(p1,p2)ems)=showp1++"-"++showp2++": no valid option - "++showemsshow(ErrorCheckpbs)=showp++": "++showBSbs++" = false"-- | This function is similar to 'templateErr'. It allows you to show the rendering error-- to the user. The context it generates always has a value named \"@pos@\", indicating-- the position where an error occured; if multiple branches failed, there is also a value-- \"endpos\", which indicates the position where the list of branches ends. Positions are-- presented with the 'posContext' function.---- Other field depend on the error. For a type mismatch, there are values \"expected\" and-- \"actual\", which are the strings \'string\', \'boolean\', \'array\' or \'record\',-- depending on what type the value should have and what type it actually has;-- there is also the \"expr\" field, which presents the list of names in the failing-- expression with the function 'listValues'.---- If the required field wasn't found in the record, then there is the value \"field\",-- which is a list of names in the failing expression, and the value \"type\", which-- shows what type that expression should have.---- If there were multiple branches, all of them failing, then, apart from \"pos\" and-- \"endpos\" fields, there is a list of errors, one for each of the branches. These-- errors are presented using the 'renderErr' function recursively.---- Finally, if the boolean value was checked and happened to be false, there would be-- the field \"check\", which, again, is a list of names in the expression, which-- evaluated to false.renderErr::RenderErr->Context()renderErr(ErrorTypec1c2pbs)=do"pos"=:posContextp"expected"=:showc1"actual"=:showc2"expr"=:listValuesbsrenderErr(ErrorFieldcpbs)=do"pos"=:posContextp"type"=:showc"field"=:listValuesbsrenderErr(ErrorOption(p1,p2)ems)=do"pos"=:posContextp1"endpos"=:posContextp2"options"=:listValues(maprenderErrems)renderErr(ErrorCheckpbs)=do"pos"=:posContextp"check"=:listValuesbs