From b1ada418d8888395823e4353114e69d4b25fc6fd Mon Sep 17 00:00:00 2001 From: TankorSmash Date: Sat, 23 May 2020 00:15:34 -0400 Subject: [PATCH] pass details to eval_exceptions for getting an object This adds the current file, line and column to an exception thrown during object lookup. Tested with `chai.eval("puts(bogusvar[0])")` and `chai.eval_file(file_containing_the_same)` and it printed the line and filename/`__EVAL__`. --- include/chaiscript/language/chaiscript_eval.hpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index d38e5aa3..ff45c9e3 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -298,7 +298,15 @@ namespace chaiscript return t_ss.get_object(this->text, m_loc); } catch (std::exception &) { - throw exception::eval_error("Can not find object: " + this->text); + File_Position file_position(this->location.start.line, this->location.start.column); + std::string what = std::string("Can not find object: ") + this->text; + if (this->location.filename != nullptr) { + const std::string& filename = *this->location.filename.get(); + throw exception::eval_error(what, file_position, filename); + } else { + const std::string& filename = "Unknown"; + throw exception::eval_error(what, file_position, filename); + } } }