首页 > 解决方案 > 如何在 extractError 中获取更多上下文?

问题描述

我有这个用于解码类型良好的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

这有效,但在失败时不会给出非常有用的错误。

Error: Failed extraction

The expression type-checked successfully but the transformation to the target
type failed with the following error:

InvalidAbsDir "foo/"

这个值可以在任何地方,所以我希望能够看到提取失败的字段名。这是可能的还是我在这里有错误的想法?

标签: dhall

解决方案


推荐阅读