GaloisInc / daedalus

The Daedalus data description language
BSD 3-Clause "New" or "Revised" License
66 stars 11 forks source link

Impoverished error reporting for TH-generated haskell #371

Open kquick opened 3 months ago

kquick commented 3 months ago

Given a fairly simple parser for "key=value" style input names_params.txt and using the compileDDLWith TH-generated parser, there is not much error information provided on parse failures.

ghci> runDParser $ pMain $ newInput "test" $ encodeUtf8 " min-length = 5; max-length=8; min-longth=3"
Left (ParseError {peSource = FromSystem, peLoc = "", peInput = Stream { off  = 31, len  = 11, name = "test"}, peMsg = "", peStack = []})

Compare this to:

$ cabal run exe:daedalus run -- names_params.ddl -i <(echo " min-length = 5; max-length=8; min-longth=3")
--- Parse error:
[offset: 36]
  • expected 'e' while matching "min-length"
  • see grammar at: names_params.ddl:25:5--25:19
  • context:
      • names_params.ddl:4:10--4:28
      • names_params.ddl:13:69--13:80
      • names_params.ddl:13:76--13:80
      • minLength
      • names_params.ddl:20:17--20:47
  • input trace:
      /dev/fd/63
        0--36
File context:
Length: 40 (0x28) bytes
0000:                2d 6c 65 6e  67 74 68 20  3d 20 35 3b       -length = 5;
0010:   20 6d 61 78  2d 6c 65 6e  67 74 68 3d  38 3b 20 6d    max-length=8; m
0020:   69 6e 2d 6c  6f 6e 67 74  68 3d 33 0a     in-longth=3.

Notably: