This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
MindenCucc's profile picture

Unable to debug program

Started by MindenCucc, 18 June 2015 - 05:56 PM
MindenCucc #1
Posted 18 June 2015 - 07:56 PM
Hi!

My problem is that I wrote a program that prints out a stacktrace of the running program if something errors, but if the window API errors, the computer just turns off with a "Goodbye" message.

My "debugger":

Spoiler

local function trace(ignore, level)
level = type(level) == "number" and level
local errorLevel = 3 + (type(ignore) == "number" and ignore or 0)
local errorDiff = errorLevel
local errorPos
local result = {}
repeat
  errorPos = select(2, xpcall(function() error("@", errorLevel) end, function(shit) return shit end))
  if errorPos ~= nil then errorPos = errorPos:match("(.+): @") end
  if errorPos then
   table.insert(result, errorPos)
   errorLevel = errorLevel + 1
   if errorLevel - errorDiff == level then return result end
  end
until not errorPos
return result
end

local function ejj(ejjdata)
  print("Press a key to show error")
  os.pullEvent("key")
  local tracd = trace()
  print(ejjdata)
  for k,v in pairs(tracd) do
	print("- "..v)
	sleep(0.2)
  end
  return ejjdata--.."\n- "..table.concat(, "\n- ")
end

local function loadfunc(feil, name)
  local handel = fs.open(fs.combine(feil, ""), "r")
  if not handel then return false, "Unable to load "..feil end
  local kernelstr = handel.readAll()
  handel.close()
  return loadstring(kernelstr, name)
end

local function dofunc(feil, name, err, ...)
  local func, ejj = loadfunc(feil, name)
  if not func then return nil, ejj end
  local argz = {...}
  if err then return xpcall(function() func(unpack(argz)) end, err) else return pcall(func, unpack(argz)) end
end

local argz = {...}

dofunc(argz[1], "DebuggerD", ejj, unpack(argz, 2))

I can't find the location of the error in the main file, because it's really big.

Edit: is it possible to break out of the derpy window API in the multishell? Because it caused a lot of headaches because of this bug :(/>
Edited on 18 June 2015 - 05:59 PM
Bomb Bloke #2
Posted 18 June 2015 - 11:57 PM
Edit: is it possible to break out of the derpy window API in the multishell? Because it caused a lot of headaches because of this bug :(/>

term.redirect(term.native())
MindenCucc #3
Posted 19 June 2015 - 12:48 AM
Oh, okay, thanks :D/> I totally forgot that :P/> But since I used wrapped versions of set*Color-s, I just inserted an error-checking snippet, and now it doesn't turn off on term API error :D/>