I have this for decoding well-typed Path
s
pathDecoder f opts =
Decoder
{ extract = extractPath
, expected = expectedPath
}
where
filePathDecoder :: Decoder FilePath
filePathDecoder = autoWith opts
extractPath expression =
case extract filePathDecoder expression of
Success x -> case f x of
Left exception -> Dhall.extractError (T.pack $ show exception)
Right path -> Success path
Failure e -> Failure e
expectedPath = expected filePathDecoder
instance FromDhall (Path Abs Dir) where
autoWith options = pathDecoder parseAbsDir options
This works, but doesn't give very helpful errors on failure.
Error: Failed extraction
The expression type-checked successfully but the transformation to the target
type failed with the following error:
InvalidAbsDir "foo/"
This value could be anywhere, so I'd like to be able to see the fieldname where the extraction failed. Is this possible or do I have the wrong idea here?