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__`.
This commit is contained in:
TankorSmash 2020-05-23 00:15:34 -04:00 committed by GitHub
parent 6abbd9dd1b
commit b1ada418d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -298,7 +298,15 @@ namespace chaiscript
return t_ss.get_object(this->text, m_loc); return t_ss.get_object(this->text, m_loc);
} }
catch (std::exception &) { 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);
}
} }
} }