Commit Graph

29 Commits

Author SHA1 Message Date
Kodi Arfer 80eb27906a Update copyright years 2020-01-09 14:05:12 -05:00
Ryan Gonzalez 0579561b83 Drop clint for colors in favor of colorama
Closes #1820.
2019-10-08 09:50:15 -05:00
Brandon T. Willard 9e62903d8a Add special exception and handling for wrapper errors 2019-02-07 13:45:41 -05:00
Brandon T. Willard 4ae4baac2a Cache command line source for exceptions
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/hy#1397.
2019-02-07 13:45:41 -05:00
Brandon T. Willard fb6feaf082 Improve correspondence with Python errors and console behavior
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/hy#1486.
2019-02-07 13:45:41 -05:00
Brandon T. Willard cadfa4152b Make colored output configurable
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/hy#1429, closes hylang/hy#1510.
2019-02-07 13:43:58 -05:00
Brandon T. Willard e468d5f081 Refactor REPL error handling and filter Hy internal trace output
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.
2019-02-07 13:43:58 -05:00
Brandon T. Willard 51c7efe6e8 Retain compiled source and file information for exceptions
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/hy#657.
2019-02-07 13:43:58 -05:00
Kodi Arfer 62638b44a3 Update copyright years 2019-02-07 08:57:35 -05:00
Kodi Arfer 6de7ddfee5 Update copyright years 2018-01-01 10:38:33 -05:00
Ryan Gonzalez e0e664c030
Merge branch 'master' into letmacro 2017-11-01 09:39:18 -05:00
gilch 3707681056 make deftag/defmacro macros, not special forms 2017-10-29 17:52:40 -06:00
Kodi Arfer 39785b4657 Fix a crash in HyTypeError.__str__ 2017-09-20 10:40:52 -07:00
Kodi Arfer 2eb81864df Make all files comply with license-header policy 2017-04-27 14:16:57 -07:00
Andrew Scorpil 7dcc583d63 Fix issue #982: UTF-8 encode error message before passing it to clint. 2015-12-14 21:55:53 +01:00
gilch e8d26f1067 remove throw in favor of raise 2015-08-09 00:52:42 -06:00
Zack M. Davis 4bea6dc59e distinguish IOError when loading file from that raised by program itself
Previously, Hy scripts that raised a subclass of IOError would be caught
by code intended to deal with IOErrors raised when Hy couldn't import
the script itself, resulting in either a misleading "Can't open file"
error message, or a misleading TypeError traceback from not being able
to format the "Can't open file" message (for IOErrors for which the
errno attribute was None). This commit (a straightforward implementation
of the idea proposed by @slimetree in #714) introduces a new HyIOError
class, raises that when `import_file_to_hst` can't open the file path,
and catches it in the `cmdline_handler`.

This is believed to fix #513, #714, and #727.
2015-02-16 14:27:18 -08:00
Berker Peksag 94362e903d Add clint as a dependency.
Since clint 0.3, it supports Python 3.
2014-12-06 21:15:59 +02:00
Kartik Mistry 909981dd23 Typo fixes in comments
Signed-off-by: Kartik Mistry <kartik.mistry@gmail.com>
2014-05-02 21:31:51 +05:30
Christopher Allan Webber d93f304220 Fix errors on Python 3.
Some unicode issues were fixed for Python 2 in 75748eb05d
but broke pretty much all Python 3 exceptions in Hy.
2014-02-23 17:16:56 -06:00
Halit Alptekin 75748eb05d Fix unicode error #483 2014-01-29 15:58:49 +02:00
Bob Tolbert 5040c29946 Cleaning up some comments from berker 2013-12-31 09:56:03 -07:00
Bob Tolbert 765dba3e56 More updates, including from Foxboron, for errors like (for) 2013-12-31 09:56:03 -07:00
Foxboron f064d3f121 Errors into errors.py, added HyMacroExpansionError, fixed macro arg fail 2013-12-31 09:56:03 -07:00
Bob Tolbert f6160c755a Much better version of new error messages.
This version is much simpler.

At the point that the exception is raised, we don't have access to
the actual source, just the current expression. but as the
exception percolates up, we can intercept it, add the source and
the re-raise it.

Then at the final point, in the cmdline handler, we can choose to
let the entire traceback print, or just the simpler, direct error
message.

And even with the full traceback, the last bit is nicely formatted
just like the shorter, simpler message.

The error message is colored if clint is installed, but to avoid
yet another dependency, you get monochrome without clint.

I'm sure there is a better way to do the markup, the current method
is kludgy but works.

I wish there was more shared code between HyTypeError and LexException
but they are kind of different in some fundamental ways.

This doesn't work (yet) with runtime errors generated from Python,
like NameError, but I have a method that can catch NameError and turn it
into a more pleasing output.

Finally, there is no obvious way to raise HyTypeError from pure Hy code,
so methods in core/language.hy throw ugly TypeError/ValueError.
2013-12-31 09:56:03 -07:00
Paul R. Tagliamonte 4cb4e7384e holy shit it's 2013 2013-03-18 10:27:14 -04:00
Paul R. Tagliamonte b777ac42a7 Update etc 2013-03-02 20:38:18 -05:00
Paul R. Tagliamonte 159151f847 thingthings. like licensing. 2013-03-02 20:24:32 -05:00
Paul R. Tagliamonte 84453e75d2 Thinking about a refacotr. 2013-02-28 22:27:20 -05:00