Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Long-form error messages #5

Open
nblumhardt opened this issue Oct 25, 2016 · 2 comments
Open

Long-form error messages #5

nblumhardt opened this issue Oct 25, 2016 · 2 comments

Comments

@nblumhardt
Copy link
Member

Superpower produces errors that carry a location, error message fragment, and expectations.

By default, the result types' ToString() formats these into one-line messages as in this test case:

AssertParser.FailsWithMessage(alternating, "123 abc 123 123", new SExpressionTokenizer(),
    "Syntax error (line 1, column 13): unexpected number `123`, expected atom.");

This is a good default, but in some applications (especially those that produce output for terminals) a multi-line error can provide more context.

This is an example from FParsec:

Failure: Error in Ln: 1 Col: 6
1.25E 3
     ^
Expecting: decimal digit

Using the information available to Superpower,

Unexpected number `123`, expected atom
 ---> line 1, column 13
  | 
1 | 123 abc 123 123
  |             ^^^ expected atom

It would be nice to show the preceding and following lines if available. The new rustc error formatting sets the benchmark here.

@nblumhardt
Copy link
Member Author

nblumhardt commented Oct 25, 2016

To avoid fiddling with the case of the message fragment:

Syntax error: unexpected number `123`, expected atom
 --> line 1, column 13
  | 
1 | 123 abc 123 123
  |             ^^^ expected atom

@nblumhardt
Copy link
Member Author

Made some small improvements in #38 that should help with this (see the linked screenshot and example program).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant