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

[solved] Blaiming callbacks for errors.

Started by Lupus590, 31 March 2018 - 06:58 PM
Lupus590 #1
Posted 31 March 2018 - 08:58 PM
Edit: Latest problem: http://www.computerc...post__p__276561




Original post:

I want to be able to blaim the callback for errors when they happen, unfortunatly it's not as simple as error(msg, 2).

Currently only the Checkpoint file gets blamed.

I've even got stack tracing curtisy of Apemanzilla.

Stranger still, it should be erroring but seems to not be.

View code online: https://github.com/C...0343c9c7a8b8e0b

Download latest code in game with: (note this is not the same as the above link)

pastebin run W5ZkVYSi CC-Hive Checkpoint

Run test.lua
Edited on 01 April 2018 - 02:18 PM
InDieTasten #2
Posted 31 March 2018 - 09:32 PM
I don't have a client at hand to run your code, and your question really leaves a lot of room for interpretation. Like what's the current behavior and desired behavior of your code. But I will formulate an equally vague response to that:

Note: I also have no idea what tracing curtisy of apemanzilla is.

If you run a callback passed by "user code" in your framework, you don't have to mess with error handling, as errors would point towards the definition of the callback, which happened in the "user code".
Your framework would be part of the call stack, but that is fine, but that doesn't "blame" it. It would be possible for you to catch it using pcall, but other than rethrowing you really can't do much in most scenarios, as you don't know what's about to happen in the callback. That's why it's a callback in the first place.

If you have pcall in your callstack already (for other code) before executing the callback function, then of course you need to make sure the original error bubbles up the chain without losing track of the original error message.
Sewbacca #3
Posted 31 March 2018 - 09:49 PM
I am not sure, what you want to do


local oldCallback = callback
local newCallback = function()
  local ok, err = pcall(callback)
  if not ok then
	error(err);
  end
end
would manage errors, thrown by the callback.


local callbacks = {}
function assignError(msg, id)
  callbacks[id].error = msg
  sleep(0)
end
function makeCallback(callback)
  local id = #callbacks + 1
  callbacks[id] = { callback = function()
	local co = coroutine.create(callback)
	while true do
	  if callbacks[id].error then
		error(callbacks[id].error, 1)
	  end
	  -- handle coroutine execution...
	end
  end, error = nil}
end
would assign an error to a preassigned function. Note: this is just a concept, i haven't tested anything.
Hopefully i could help.

Greetings
Sewbacca
Lupus590 #4
Posted 31 March 2018 - 10:18 PM
I am not sure, what you want to do


local oldCallback = callback
local newCallback = function()
  local ok, err = pcall(callback)
  if not ok then
	error(err);
  end
end
would manage errors, thrown by the callback.

I've kinda done that and it hasn't worked.
Lupus590 #5
Posted 31 March 2018 - 10:40 PM
SquidDev helped me on gitter resulting in this version of the code: https://github.com/CC-Hive/Checkpoint/tree/0efe3191cfda089c8d41cead0cad587ca2f66977

It works now, needs some cleanup but I should be able to manage.
Lupus590 #6
Posted 01 April 2018 - 12:30 AM
Ok. I thought I had this solved but I've got more issues, the intentional error is not working, infact the second part of the test file doesn't even run.

I even tried using the trace functionality from MBS.

https://github.com/C...39580f6bb9fc80b

I think the .checkpoint file is not being made for some reason.
Edited on 31 March 2018 - 10:34 PM
Lupus590 #7
Posted 01 April 2018 - 02:32 PM
Is half a day long enough before a bumb?
Lupus590 #8
Posted 01 April 2018 - 04:17 PM
SquidDev to the rescue again: https://github.com/CC-Hive/Checkpoint/tree/9c3ae2df6e48a2545c82eecf3c22676f4cc7cd44

Error or not, the API deleted the .checkpoint file which it was not suposed to do.