pact icon indicating copy to clipboard operation
pact copied to clipboard

Better error message when you write `boolean` instead of `bool`

Open joelburget opened this issue 6 years ago • 2 comments

@emilypi on slack:

Used boolean instead of bool as a type for a table, and this got spit back out: coin.pact:16:12: error: Expected: bool,Expected: decimal,Expected: guard,Expected: integer,Expected: keyset,Expected: list,Expected: object,Expected: string,Expected: table,Expected: time,Expected: value

joelburget avatar Apr 05 '19 21:04 joelburget

@emilypi if you still have the code i think that'd be helpful

joelburget avatar Apr 05 '19 21:04 joelburget

I think it's great to tackle this one-by-one but the real problem here is Compile where I punted on figuring out proper error semantics, at great cost to legibility of errors which took a huge dive.

If somebody can stare at https://github.com/kadena-io/pact/blob/767b70bbf042f1f40c122b9f74dff8901039a31e/src/Pact/Types/ExpParser.hs#L137, what we need is for things like userAtom <?> "expected user atom" to work properly, whereas right now the internal state of failure accumulation in megaparsec is not well-understood and as a result we get gibberish like the above.

Having said that this is one of our less incomprehensible error messages, at least it's clearly trying to match some type. This means that parseType is better-behaved than most: https://github.com/kadena-io/pact/blob/767b70bbf042f1f40c122b9f74dff8901039a31e/src/Pact/Compile.hs#L554

The other day I was going crazy trying to solve this problem, parsing the following (well, compiling, but no way to tell the difference!):

  (defschema schema-a a:integer)
  (defschema schema-b b:integer)

  (defpact tc-yield-resume-1 (foo bar x:integer) ;; line 155
    (step (if foo
              (let ((y:object{schema-a} {'a: x}))
                (yield y))
            (yield {'a: (+ x 1)})))
    (step (if bar
              (resume {'a := z}
                (let ((y:object{schema-b} {'b: (+ z 1)}))
                  (yield y)))
            (resume {'a:= z} (yield {'b: z}))))
    (step (resume {'b= q} q))
  )

The error was tests/pact/tc.repl:155:3: error: Expected: end of expression or input !!!

I leave it as an exercise to the reader to find the error :(

sirlensalot avatar Apr 06 '19 01:04 sirlensalot