diff options
author | ridiculousfish <corydoras@ridiculousfish.com> | 2014-01-08 18:20:55 -0800 |
---|---|---|
committer | ridiculousfish <corydoras@ridiculousfish.com> | 2014-01-08 18:20:55 -0800 |
commit | 0e9d159bc2e95d71ae2051957397bc689e020e42 (patch) | |
tree | f16159d6c7f14afbe37834778b4d419aa768c0a0 /reader.cpp | |
parent | d69f408b14a267ff2968f21f24241cb3e87102de (diff) |
Improvements to error reporting. In particular, we now append a newline
in reader_shell_test, so that there's always a statement terminator.
Otherwise commands like 'echo |' would not be considered an error (just
incomplete).
Diffstat (limited to 'reader.cpp')
-rw-r--r-- | reader.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
@@ -2470,21 +2470,26 @@ void reader_run_command(parser_t &parser, const wcstring &cmd) int reader_shell_test(const wchar_t *b) { + assert(b != NULL); wcstring bstr = b; + + /* Append a newline, to act as a statement terminator */ + bstr.push_back(L'\n'); + parse_error_list_t errors; int res = parse_util_detect_errors(bstr, &errors); if (res & PARSER_TEST_ERROR) { - wcstring sb; - parser_t::principal_parser().get_backtrace(bstr, errors, &sb); + wcstring error_desc; + parser_t::principal_parser().get_backtrace(bstr, errors, &error_desc); // ensure we end with a newline. Also add an initial newline, because it's likely the user just hit enter and so there's junk on the current line - if (! string_suffixes_string(L"\n", sb)) + if (! string_suffixes_string(L"\n", error_desc)) { - sb.push_back(L'\n'); + error_desc.push_back(L'\n'); } - fwprintf(stderr, L"\n%ls", sb.c_str()); + fwprintf(stderr, L"\n%ls", error_desc.c_str()); } return res; } |