feat(users/Profpatsch/whatcd-resolver): show json val on parse err
The json parsing library gives us an error path where the parse failed, which means we can index into the path to show the json value that failed us. This can be quite expensive (and large!) of course, but the error message clarity is worth it methinks. Change-Id: Icacbd799254aaecd4a939ca13e6070d68a78138d Reviewed-on: https://cl.tvl.fyi/c/depot/+/12952 Tested-by: BuildkiteCI Reviewed-by: Profpatsch <mail@profpatsch.de>
This commit is contained in:
parent
0319b5e6c0
commit
722499d8a9
5 changed files with 94 additions and 7 deletions
30
users/Profpatsch/my-prelude/src/Debug.hs
Normal file
30
users/Profpatsch/my-prelude/src/Debug.hs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
{-# LANGUAGE QuasiQuotes #-}
|
||||
|
||||
module Debug where
|
||||
|
||||
import Data.Text qualified as Text
|
||||
import Data.Text.IO qualified as Text.IO
|
||||
import Debug.Trace as Debug
|
||||
import PossehlAnalyticsPrelude
|
||||
import Pretty qualified
|
||||
|
||||
-- | 'Debug.trace' a showable value when (and only if!) it is evaluated, and pretty print it.
|
||||
traceShowPretty :: (Show a) => a -> a
|
||||
traceShowPretty a = Debug.trace (textToString $ Pretty.showPretty a) a
|
||||
|
||||
-- | 'Debug.trace' a showable value when (and only if!) it is evaluated, and pretty print it. In addition, the given prefix is put before the value for easier recognition.
|
||||
traceShowPrettyPrefix :: (Show a) => Text -> a -> a
|
||||
traceShowPrettyPrefix prefix a = Debug.trace ([fmt|{prefix}: {Pretty.showPretty a}|]) a
|
||||
|
||||
-- | Display non-printable characters as their unicode Control Pictures
|
||||
-- https://en.wikipedia.org/wiki/Unicode_control_characters#Control_pictures
|
||||
--
|
||||
-- Not all implemented.
|
||||
putStrLnShowNPr :: Text -> IO ()
|
||||
putStrLnShowNPr t =
|
||||
Text.IO.putStrLn $
|
||||
-- newlines will actually print a newline for convenience
|
||||
t
|
||||
& Text.replace "\n" "\n"
|
||||
& Text.replace "\r\n" "\n"
|
||||
& Text.replace "\t" "␉"
|
||||
Loading…
Add table
Add a link
Reference in a new issue