mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2025-12-06 16:57:04 +08:00
parent
145acd378b
commit
98c362d038
@ -480,11 +480,14 @@ namespace chaiscript
|
|||||||
/// Errors generated when loading a file
|
/// Errors generated when loading a file
|
||||||
struct file_not_found_error : std::runtime_error {
|
struct file_not_found_error : std::runtime_error {
|
||||||
explicit file_not_found_error(const std::string &t_filename) noexcept
|
explicit file_not_found_error(const std::string &t_filename) noexcept
|
||||||
: std::runtime_error("File Not Found: " + t_filename)
|
: std::runtime_error("File Not Found: " + t_filename),
|
||||||
|
filename(t_filename)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
file_not_found_error(const file_not_found_error &) = default;
|
file_not_found_error(const file_not_found_error &) = default;
|
||||||
~file_not_found_error() noexcept override = default;
|
~file_not_found_error() noexcept override = default;
|
||||||
|
|
||||||
|
std::string filename;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -241,7 +241,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
if (skip_bom(infile)) {
|
if (skip_bom(infile)) {
|
||||||
size-=3; // decrement the BOM size from file size, otherwise we'll get parsing errors
|
size-=3; // decrement the BOM size from file size, otherwise we'll get parsing errors
|
||||||
assert(size >=0 ); //and check if there's more text
|
assert(size >= 0); //and check if there's more text
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size == std::streampos(0))
|
if (size == std::streampos(0))
|
||||||
@ -394,8 +394,8 @@ explicit ChaiScript_Basic(std::unique_ptr<parser::ChaiScript_Parser_Base> &&pars
|
|||||||
{
|
{
|
||||||
for (const auto &path : m_use_paths)
|
for (const auto &path : m_use_paths)
|
||||||
{
|
{
|
||||||
|
const auto appendedpath = path + t_filename;
|
||||||
try {
|
try {
|
||||||
const auto appendedpath = path + t_filename;
|
|
||||||
|
|
||||||
chaiscript::detail::threading::unique_lock<chaiscript::detail::threading::recursive_mutex> l(m_use_mutex);
|
chaiscript::detail::threading::unique_lock<chaiscript::detail::threading::recursive_mutex> l(m_use_mutex);
|
||||||
chaiscript::detail::threading::unique_lock<chaiscript::detail::threading::shared_mutex> l2(m_mutex);
|
chaiscript::detail::threading::unique_lock<chaiscript::detail::threading::shared_mutex> l2(m_mutex);
|
||||||
@ -411,7 +411,11 @@ explicit ChaiScript_Basic(std::unique_ptr<parser::ChaiScript_Parser_Base> &&pars
|
|||||||
}
|
}
|
||||||
|
|
||||||
return retval; // return, we loaded it, or it was already loaded
|
return retval; // return, we loaded it, or it was already loaded
|
||||||
} catch (const exception::file_not_found_error &) {
|
} catch (const exception::file_not_found_error &e) {
|
||||||
|
if (e.filename != appendedpath) {
|
||||||
|
// a nested file include failed
|
||||||
|
throw;
|
||||||
|
}
|
||||||
// failed to load, try the next path
|
// failed to load, try the next path
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
11
unittests/failed_deep_include.chai
Normal file
11
unittests/failed_deep_include.chai
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
use("failed_deep_include.inc")
|
||||||
|
assert_true(false);
|
||||||
|
} catch (e) {
|
||||||
|
puts("Caught exception while trying to use file");
|
||||||
|
assert_equal(e.what(), "File Not Found: totally_missing_file.inc");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
3
unittests/failed_deep_include.inc
Normal file
3
unittests/failed_deep_include.inc
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
use("totally_missing_file.inc");
|
||||||
|
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user