From 7d7e95006fa70e3f348ce118e756207d57040d93 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Wed, 6 Apr 2022 20:24:23 +0200 Subject: main: abort when failing to load a preload library Do not continue loading other libraries or executing the main code if loading one of the preload libraries fails. Signed-off-by: Jo-Philipp Wich --- main.c | 8 ++++++-- tests/cram/test_basic.t | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/main.c b/main.c index e066961..7fd50d9 100644 --- a/main.c +++ b/main.c @@ -435,7 +435,7 @@ parse_library_load(char *opt, uc_vm_t *vm) ucv_put(lib); if (!ctx) - return false; + return vm->exception.type == EXCEPTION_NONE; ucv_object_add(uc_vm_scope_get(vm), name ? name : p, ctx); @@ -557,7 +557,11 @@ main(int argc, char **argv) break; case 'l': - parse_library_load(optarg, &vm); + if (!parse_library_load(optarg, &vm)) { + rv = 1; + goto out; + } + break; case 'c': diff --git a/tests/cram/test_basic.t b/tests/cram/test_basic.t index b85167f..7308002 100644 --- a/tests/cram/test_basic.t +++ b/tests/cram/test_basic.t @@ -79,19 +79,19 @@ check that ucode prints greetings: check that ucode provides proper error messages: - $ ucode -l foo + $ touch lib.uc; ucode -l lib Require either -e expression or source file [1] $ ucode -l foo -e ' ' Runtime error: No module named 'foo' could be found - [254] + [1] $ touch moo; ucode -l foo moo Runtime error: No module named 'foo' could be found - [254] + [1] check that ucode can load fs module: -- cgit v1.2.3