-
Notifications
You must be signed in to change notification settings - Fork 372
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
Generate more concise syntax and compiler errors #1687
Conversation
5ca669d
to
1b796e5
Compare
It looks like a
|
Looks like it's pointing at the end of the file, where the paren isn't closed, but the indenting in the print-out stops after |
1b796e5
to
79c54e1
Compare
Just pushed a fix that should take care of that print-out. > hy test.hy
Traceback (most recent call last):
File "/home/bwillard/apps/anaconda3/envs/hy-dev/bin/hy", line 11, in <module>
load_entry_point('hy', 'console_scripts', 'hy')()
File "/home/bwillard/apps/anaconda3/envs/hy-dev/lib/python3.6/runpy.py", line 261, in run_path
code, fname = _get_code_from_file(run_name, path_name)
File "<frozen importlib._bootstrap_external>", line 781, in get_code
File "/tmp/test.hy", line 27
(
^
hy.lex.exceptions.PrematureEndOfInput: Premature end of input |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a huge commit. Can you group your changes into logical units instead?
5e5778e
to
31a630d
Compare
Would you please:
Let me know when the PR is ready for review. |
8477d1e
to
a8d6a48
Compare
All right, I further separated those commits by their functionality. Unfortunately, the first one is necessarily large-ish, due to how much code it affects; however, most of the changes are simple (e.g. adding new arguments for source and filename). |
It's okay. There will at least be fewer added lines once you introduce a helper for |
a8d6a48
to
d7bb916
Compare
All right, added some helpers for the relevant errors. |
You mean like this?
Why not something like this?
Then you don't have to pass in |
No, the helper functions are the additional class methods in Sure, a method in the compiler could be added, too. |
d7bb916
to
6839bce
Compare
Added a |
Much nicer. |
231ad2d
to
285b9e5
Compare
The commit message for "Make colored output configurable" mentions It seems that At least at the tip of the PR, there's a regression such that a return value of |
f367e3f
to
ace7190
Compare
I'm sorry, Brandon, I've only just noticed that you updated this. It seems that GitHub doesn't send a notification for force-pushes. I'll continue review soon. |
No problem; I try to respond with a message after force-pushes, since I also don't recall ever getting such notifications. I believe I've addressed the matters in your last comment, except for the REPL return value. Is it by design that it doesn't display The Python REPL doesn't either, but, if I recall, Clojure and some other Lisps do. The only immediate advantage— that I can think of right now—involves code that reads from the REPL output (e.g. Regardless, it's easy to change. |
Yeah, the non-display of |
So do that, if you don't mind, and then I'll look again. |
51ec427
to
a4c084f
Compare
All right, now it doesn't print |
Thanks. I just reviewed more of these commits and made more changes and I'm getting a "Permission denied" error when I try to push. Do you have the option to accept changes from reviewers switched off? |
Yes |
Can you turn it back on? Otherwise, I don't think there's a way for me to cleanly rewrite history. You can make a copy first with |
I'm fine with one reasonably sized set of final reviewer changes—which is what I thought the last one was—but a review process consisting of rebases is too confusing and time consuming. Please describe the changes you think are necessary to merge this PR. |
I could save up all my edits till I'm done reviewing the entire PR, but I thought you'd rather get them as I make them, rather than get a giant stack of them all at once after a long time. I've pushed my current version of |
So far, at any rate, I've reviewed up to and including "Improve correspondence with Python errors and console behavior", and made the following notable changes:
|
Okay, all done. Sorry for the long delay. I had a busy week and I expected there'd be a lot more work to do here, but I made only minor changes to the last two commits. |
If all looks good to you, replace your version of the branch with mine and we should be good to merge (pending the final Travis check). |
Finally had a chance to look at your branch; give it a push. |
Okay, I'll do it this afternoon. There will probably be some merge conflicts, but if those can be smoothed out without major issues and Travis has no surprises in store, I'll merge. |
And standardize the indentation of these calls.
This commit refactors the exception/error classes and their handling. It also retains Hy source strings and their originating file information, when available, all throughout the core parser and compiler functions. As well, with these changes, calling code is no longer responsible for providing source and file details to exceptions, Closes hylang#657.
These changes make the Hy REPL more closely follow `code.InteractiveConsole`'s class interface and provide minimally intrusive traceback print-out filtering via a context manager that temporarily alters `sys.excepthook`. In other words, exception messages from the REPL will no longer show Hy internal code (e.g. importer, compiler and parsing functions). The boolean variable `hy.errors._hy_filter_internal_errors` dynamically enables/disables trace filtering, and the env variable `HY_FILTER_INTERNAL_ERRORS` can be used as the initial value.
Colored exception output is now disabled by default and configurable through `hy.errors._hy_colored_errors` and the environment variable `HY_COLORED_ERRORS`. Likewise, Hy model/AST color printing is now configurable and disabled by default. The corresponding variables are `hy.models._hy_colored_ast_objects` and `HY_COLORED_AST_OBJECTS`. Closes hylang#1429, closes hylang#1510.
Compiler and command-line error messages now reflect their Python counterparts. E.g. where Python emits a `SyntaxError`, so does Hy; same for `TypeError`s. Multiple tests have been added that check the format and type of raised exceptions over varying command-line invocations (e.g. interactive and not). A new exception type for `require` errors was added so that they can be treated like normal run-time errors and not compiler errors. The Hy REPL has been further refactored to better match the class-structured API. Now, different error types are handled separately and leverage more base class-provided functionality. Closes hylang#1486.
Source entered interactively can now be displayed in traceback output. Also, the REPL object is now available in its namespace, so that, for instance, display options--like `spy`--can be turned on and off interactively. Closes hylang#1397.
a4c084f
to
9e62903
Compare
This PR refactors the exception/error classes and their handling, keeps Hy source strings and their corresponding file information (if any) closer to the origin of an exception (so that calling code isn't responsible for annotating exceptions), and provides minimally intrusive traceback print-out filtering via a context manager that temporarily alters
sys.excepthook
(this is automatically enabled for Hy command-line sessions).New environment and package variables have been introduced, as well:
HY_COLORED_ERRORS
, and package variable,hy.errors._hy_colored_errors
, that enables/disables manual error coloring, andHY_COLORED_AST_OBJECTS
, and package variable,hy.models._hy_colored_ast_objects
, that enables/disables AST object coloring.Also, source caching has been added to the Hy interpreter. It's modeled after the approach used by IPython via
linecache
. Now, for example, traces will show the relevant source lines for functions, objects, etc., defined exclusively in the REPL (see the example below).require
#1486 (the error message part)Notes
As mentioned above, the
sys.excepthook
provided here only hides internal frames from the traceback print-out, and not the actual traceback object, so, for instance, it does not affect the stack inpdb
.There are other, more powerful and direct approaches that involve altering and/or creating low-level traceback objects (e.g. Jinja's). These allow for a better debugging experience (e.g. without any compiler or parser frames), but they're also more complicated and distribution dependent. In the long run, I think it's better to have custom tracebacks, so I'll keep an eye on good/better ways to do this; for example, this approach is interesting.
Example
Before
After