trace - Simple stack traces for errors
apemanzilla 01 Nov 2016
As it turns out, CC supports xpcall, which is a pretty neat function that allows hackishly getting more detailed stack traces by abusing error levels. I used this to write trace:
In this example, example.lua is the following file:
It's really easy to use trace - just download with pastebin get CYQp63kb trace, and then run any command preceded by trace (see example). When/if the program crashes, a stacktrace will be generated automatically. This is incredibly useful for debugging large projects as it allows you to see exactly what caused the error.
If you're curious as to how it works you're welcome to read the code, but as I said earlier, it's pretty hacky.
Edited by apemanzilla, 01 November 2016 - 02:01 PM.
In this example, example.lua is the following file:
local function a() error("example error") --# line 2 end local function b() a() --# line 6 end local function c() b() --# line 10 end c() --# line 13
It's really easy to use trace - just download with pastebin get CYQp63kb trace, and then run any command preceded by trace (see example). When/if the program crashes, a stacktrace will be generated automatically. This is incredibly useful for debugging large projects as it allows you to see exactly what caused the error.
If you're curious as to how it works you're welcome to read the code, but as I said earlier, it's pretty hacky.
Edited by apemanzilla, 01 November 2016 - 02:01 PM.
Bomb Bloke 08 Nov 2016
It could use some checks to ensure its output will be visible; this window-API-crashing snippet results in blankness for eg:
I suspect this script may be one I'll frequently be pointing AaP posters to, however.
term.setTextColour(123) print("hello")
I suspect this script may be one I'll frequently be pointing AaP posters to, however.
apemanzilla 08 Nov 2016
Bomb Bloke, on 08 November 2016 - 02:05 PM, said:
It could use some checks to ensure its output will be visible; this window-API-crashing snippet results in blankness for eg:
I suspect this script may be one I'll frequently be pointing AaP posters to, however.
term.setTextColour(123) print("hello")
I suspect this script may be one I'll frequently be pointing AaP posters to, however.
That's a pretty evil snippet, I'm blaming the window API for that one, hehe. Regardless, I've fixed this particular issue - just redownload from the same PB code.
While it does blame the (technically correct) call to print, it would be more helpful if the window API simply errored if you attempt to set a non-blittable color.
I've also implemented a new feature - if the original error thrown by the program does not contain the correct source (file and line number) then it will show an additional entry containing the correct source at the beginning of the stacktrace. (This can happen when a program is terminated, which omits the source, or when a non-one error level is used, which changes the source)
Edited by apemanzilla, 08 November 2016 - 03:40 PM.
apemanzilla 08 Nov 2016
Lyqyd 08 Nov 2016
I'm not really sure why the window API doesn't just do what the term API does and select the color represented by the highest true bit:
But erroring immediately would be preferable to creating a time bomb!
term.setTextColor(127) --# 64 term.setTextColor(129) --# 128
But erroring immediately would be preferable to creating a time bomb!
minebuild02 17 Nov 2016
Could I use this in my OS?
Edited by minebuild02, 17 November 2016 - 03:47 PM.
Edited by minebuild02, 17 November 2016 - 03:47 PM.
apemanzilla 17 Nov 2016
apemanzilla 07 Mar 2018
Minor update - trace now supports pcall and xpcall - if you use these in your program, they'll give you a stack trace instead of an error message when you run your program via trace. The original paste has been updated, so simply redownload it to get the update.
Edited by apemanzilla, 07 March 2018 - 08:17 PM.
Edited by apemanzilla, 07 March 2018 - 08:17 PM.
Luca_S 08 Aug 2018
Awesome program!
I tried to use it with coroutines and I got something working, but, considering I have absolutely no idea how it works , it is also pretty much hacked together.
https://pastebin.com/hGgTDpkP
I would be happy if you could tell me if there's something I could improve about it.
If you'd allow me to, I'm probably going to use this in my OS to build full stacktraces if an app crashes. Of course you would get proper credit.
I tried to use it with coroutines and I got something working, but, considering I have absolutely no idea how it works , it is also pretty much hacked together.
https://pastebin.com/hGgTDpkP
I would be happy if you could tell me if there's something I could improve about it.
If you'd allow me to, I'm probably going to use this in my OS to build full stacktraces if an app crashes. Of course you would get proper credit.
apemanzilla 08 Aug 2018
Luca_S, on 08 August 2018 - 08:54 AM, said:
Awesome program!
I tried to use it with coroutines and I got something working, but, considering I have absolutely no idea how it works , it is also pretty much hacked together.
https://pastebin.com/hGgTDpkP
I would be happy if you could tell me if there's something I could improve about it.
If you'd allow me to, I'm probably going to use this in my OS to build full stacktraces if an app crashes. Of course you would get proper credit.
I tried to use it with coroutines and I got something working, but, considering I have absolutely no idea how it works , it is also pretty much hacked together.
https://pastebin.com/hGgTDpkP
I would be happy if you could tell me if there's something I could improve about it.
If you'd allow me to, I'm probably going to use this in my OS to build full stacktraces if an app crashes. Of course you would get proper credit.
Looks OK. I'm fine with you redistributing and using the code.