Merge pull request #3112 from Ad115/Ad115

Added emphasis to the error source
This commit is contained in:
Anthony Scopatz 2019-05-06 15:52:49 -04:00 committed by GitHub
commit cc55c678c2
Failed to generate hash of commit
3 changed files with 25 additions and 2 deletions

23
news/prompt_error.rst Normal file
View file

@ -0,0 +1,23 @@
**Added:**
* <news item>
**Changed:**
* Errors while formatting the prompt are highlighted for easier debugging.
**Deprecated:**
* <news item>
**Removed:**
* <news item>
**Fixed:**
* <news item>
**Security:**
* <news item>

View file

@ -94,7 +94,7 @@ def test_format_prompt_with_invalid_func(formatter, xonsh_builtins):
def test_format_prompt_with_func_that_raises(formatter, capsys, xonsh_builtins):
xonsh_builtins.__xonsh__.env = Env()
template = "tt {zerodiv} tt"
exp = "tt (ERROR:zerodiv) tt"
exp = "tt {BACKGROUND_RED}{ERROR:zerodiv}{NO_COLOR} tt"
fields = {"zerodiv": lambda: 1 / 0}
obs = formatter(template, fields)
assert exp == obs

View file

@ -83,7 +83,7 @@ class PromptFormatter:
except Exception:
print("prompt: error: on field {!r}" "".format(field), file=sys.stderr)
xt.print_exception()
value = "(ERROR:{})".format(field)
value = "{{BACKGROUND_RED}}{{ERROR:{}}}{{NO_COLOR}}".format(field)
return value