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

Debugging threads?

Question

Posted

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?

3 answers to this question

Recommended Posts

  • 0
Posted

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

usage:

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
traceback:
at line bla-bla-bla in function bla-bla-bla
...

]]

 

  • 0
Posted

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)
  thread.create(function() 
    local syc, e = xpcall(func, debug.traceback)

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

--disclamer: this is not tested

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...

Important Information

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