Vanderhoof / PyDBML

DBML parser and builder for Python
MIT License
101 stars 12 forks source link

Obscure issues #3

Closed aviallon closed 2 years ago

aviallon commented 3 years ago

When a error is found in the DBML input, it is very hard to understand what is happening. The only work-arround is to progressively comment each line to finally understand where it is.

Vanderhoof commented 3 years ago

Hi, @aviallon! Thanks for the feedback

I just tried to introduce a syntax error by removing a quote after quantity

...
Table "order_items" {
  "order_id" int
  "product_id" int
  "quantity int [default: 1]
}

After trying to parse the file Python threw me an exception:

>>> parsed = PyDBML(Path('test_schema.dbml'))
pyparsing.ParseException: Expected "}", found '"'  (at char 433), (line:28, col:3)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../parser.py", line 47, in __new__
    return cls.parse(source)
  File ".../parser.py", line 58, in parse
    return PyDBMLParseResults(text)
  File ".../parser.py", line 84, in __init__
    self._syntax.parseString(self.source, parseAll=True)
  File ".../pyparsing.py", line 1955, in parseString
    raise exc
  File ".../pyparsing.py", line 4065, in parseImpl
    raise ParseSyntaxException._from_exception(pe)
pyparsing.ParseSyntaxException: Expected "}", found '"'  (at char 433), (line:28, col:3)

It's not a very accurate exception, it points not to the missing quote but to the beginning of faulty line, but the line number is correct and by studying it you usually can guess what's wrong with it.

Are you talking about this issue or you met more confusing error messages?

In any case, I'll try to find out if it's possible to make error messages more exact