Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0


So, I'm developing a program which uses event.listen(), and debugging them is a pain because of lines like these: 

bad argument #1 (string expected, got nil)

How am I supposed to know where the error is when there is no location information? So is there a way to get the full error details somehow?

Share this post

Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0

the function xpcall should give you a traceback witch will tell you what line the error is genratet


syc, e = xpcall(functionToRun, debug.traceback)
--[[ syc: true or false: where false means that there was an error
e: a full error message i.e:
line bla-bla-bla: bad argument bla-bla-bla
at line bla-bla-bla in function bla-bla-bla



Share this post

Link to post
Share on other sites
  • 0

also treads doesn't create an critical error in the main scope so a great way to run a thread in terms of debuging is by printing the error on the screen and start a blocking function such as computer.beep()


funciton runThreadWithExelentDebuging(func)
    local syc, e = xpcall(func, debug.traceback)

    if syc == false then
      //syc is false this means an error was genrated in func
      require("computer").beep(500,10) //calling computer.beep to avoid other threads or the main scope to redraw the screen

--disclamer: this is not tested


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.