diff options
author | Jo-Philipp Wich <jo@mein.io> | 2021-04-26 20:05:51 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2021-04-27 12:18:32 +0200 |
commit | 9ef693edd6c9572c0ab0b1381fe5e65a8430e8fb (patch) | |
tree | 113914d774f7459bd77dbafaf719dd04e33fe15c | |
parent | 6def9fcf1cdec117866877aa5e7241e23bdc8c23 (diff) |
vm: improve context for early errors
Print "Before start of program" for errors that are raised before entering
main(), e.g. on module preloading failure.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r-- | tests/cram/test_basic.t | 4 | ||||
-rw-r--r-- | vm.c | 4 |
2 files changed, 5 insertions, 3 deletions
diff --git a/tests/cram/test_basic.t b/tests/cram/test_basic.t index 5061d37..982d58a 100644 --- a/tests/cram/test_basic.t +++ b/tests/cram/test_basic.t @@ -37,13 +37,13 @@ check that ucode provides proper error messages: $ ucode -m foo -s '' Runtime error: No module named 'foo' could be found - At offset 0 + At start of program [1] $ touch moo; ucode -m foo -i moo Runtime error: No module named 'foo' could be found - At offset 0 + At start of program [1] @@ -842,8 +842,10 @@ uc_vm_get_error_context(uc_vm *vm) if (offset) format_error_context(buf, frame->closure->function->source, stacktrace, offset); + else if (frame->ip != chunk->entries) + ucv_stringbuf_printf(buf, "At instruction %zu", (frame->ip - chunk->entries) - 1); else - ucv_stringbuf_printf(buf, "At offset %zu", (frame->ip - chunk->entries) - 1); + ucv_stringbuf_append(buf, "At start of program"); ucv_object_add(ucv_array_get(stacktrace, 0), "context", ucv_stringbuf_finish(buf)); |