Improve config load error message in runtime
This commit is contained in:
parent
3856a03ec1
commit
c45a270a0b
|
@ -16,10 +16,11 @@ extern "C" int main(int argc, char const * const * argv) {
|
||||||
bool is_config_loaded{false};
|
bool is_config_loaded{false};
|
||||||
|
|
||||||
system.res_fs().read_file(config_path, [&](coral::readable const & file) {
|
system.res_fs().read_file(config_path, [&](coral::readable const & file) {
|
||||||
kym::vm vm{&system.thread_safe_allocator(),
|
coral::allocator * const allocator{&system.thread_safe_allocator()};
|
||||||
[&system](coral::slice<char const> const & error_message) {
|
|
||||||
system.log(app::log_level::error, error_message);
|
kym::vm vm{allocator, [&system](coral::slice<char const> const & error_message) {
|
||||||
}};
|
system.log(app::log_level::error, error_message);
|
||||||
|
}};
|
||||||
|
|
||||||
if (!vm.init({.datastack_size = 64, .callstack_size = 64})) {
|
if (!vm.init({.datastack_size = 64, .callstack_size = 64})) {
|
||||||
system.log(app::log_level::error, "failed to allocate memory for config vm");
|
system.log(app::log_level::error, "failed to allocate memory for config vm");
|
||||||
|
@ -27,7 +28,7 @@ extern "C" int main(int argc, char const * const * argv) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
coral::stack<coral::u8> script_source{&system.thread_safe_allocator()};
|
coral::stack<coral::u8> script_source{allocator};
|
||||||
coral::u8 stream_buffer[1024]{0};
|
coral::u8 stream_buffer[1024]{0};
|
||||||
|
|
||||||
if (!coral::stream(coral::sequence_writer{&script_source}, file, stream_buffer).is_ok())
|
if (!coral::stream(coral::sequence_writer{&script_source}, file, stream_buffer).is_ok())
|
||||||
|
@ -51,7 +52,7 @@ extern "C" int main(int argc, char const * const * argv) {
|
||||||
vm.with_object(config.get_field("title"), [&](kym::bound_object & title) {
|
vm.with_object(config.get_field("title"), [&](kym::bound_object & title) {
|
||||||
coral::stack<coral::u8, 128> title_buffer{&system.thread_safe_allocator()};
|
coral::stack<coral::u8, 128> title_buffer{&system.thread_safe_allocator()};
|
||||||
|
|
||||||
if (!title.stringify(coral::sequence_writer(&title_buffer)).is_ok()) {
|
if (!title.stringify(coral::sequence_writer{&title_buffer}).is_ok()) {
|
||||||
system.log(app::log_level::error,
|
system.log(app::log_level::error,
|
||||||
"failed to decode `title` property of config");
|
"failed to decode `title` property of config");
|
||||||
|
|
||||||
|
@ -64,7 +65,21 @@ extern "C" int main(int argc, char const * const * argv) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!is_config_loaded) return coral::u8_max;
|
if (!is_config_loaded) {
|
||||||
|
coral::stack<coral::u8> error_message{&system.thread_safe_allocator()};
|
||||||
|
|
||||||
|
{
|
||||||
|
coral::sequence_writer error_writer{&error_message};
|
||||||
|
|
||||||
|
if (!error_writer(coral::slice{"failed to load "}.as_bytes()).is_ok())
|
||||||
|
return coral::u8_max;
|
||||||
|
|
||||||
|
if (!error_writer(config_path.as_slice().as_bytes()).is_ok())
|
||||||
|
return coral::u8_max;
|
||||||
|
}
|
||||||
|
|
||||||
|
return coral::u8_max;
|
||||||
|
}
|
||||||
|
|
||||||
// app::canvas canvas_2d();
|
// app::canvas canvas_2d();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue