From be15f695222f3aca50c0b10bfa5d1a55418ecbb9 Mon Sep 17 00:00:00 2001 From: aaron <83140718+centau@users.noreply.github.com> Date: Mon, 21 Aug 2023 21:57:11 +0100 Subject: [PATCH] Improve error trace reporting --- src/throw.luau | 19 ++++++++++++++++++- todo.md | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/throw.luau b/src/throw.luau index 121d51c..3058672 100644 --- a/src/throw.luau +++ b/src/throw.luau @@ -1,8 +1,25 @@ +local function get_path(s) + if string.sub(s, #s - 4, #s) == ".luau" then + s = string.sub(s, 1, #s - 5) + print("test, ", s) + end + + return string.split(s, string.match(s, "%w+/") and "/" or ".") +end + +local root do + local path = get_path(debug.info(1, "s")) + root = path[#path - 1] +end + local function throw(msg: string) local stack = 1 - while debug.info(stack, "s") == debug.info(1, "s") do + local path = get_path(debug.info(stack, "s")) + + while path[#path] == root or path[#path - 1] == root do stack += 1 + path = get_path(debug.info(stack, "s")) end error(msg, stack) diff --git a/todo.md b/todo.md index f0a1c85..e3577ea 100644 --- a/todo.md +++ b/todo.md @@ -5,7 +5,7 @@ - better error reporting and stack traces in strict mode - auto-enable of strict mode depending on compiler optimizaton level - check smoothness of spring at high frequency updates -- review alternative to nested properties, merge function +- aggregate initialization of properties - implement from solid - [x] onCleanup > `cleanup()` - [x] Index > `indexes()`