1

I have this for decoding well-typed Paths

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?

  • You will probably want to open an issue against the Haskell implementation of Dhall since I don't believe this is possible using the current API: https://github.com/dhall-lang/dhall-haskell/issues – Gabriella Gonzalez Jul 08 '21 at 21:51

0 Answers0