How to access the stack trace from the external API

Typically: "How do I... ", "How can I... " questions
Post Reply
agsdyson
Posts: 30
Joined: 13 Feb 2019, 14:02

How to access the stack trace from the external API

Post by agsdyson » 07 Mar 2019, 15:43

I'm using python to call the external API to do some simulation.

if I use the python external API to call "sim.setObjectName()" with the incorrect arguments the stack trace output is:

Code: Select all

Lua runtime error: [string "CHILD SCRIPT remoteApiCommandServer"]:51: The function requires more arguments. (sim.setObjectName)
stack traceback:
	[C]: in function 'setObjectName'
	.../workspaceAnalysis/pyvrep/scenes/lua/createRobot.lua:51: in function 'createJoint'
	.../workspaceAnalysis/pyvrep/scenes/lua/createRobot.lua:68: in function <.../workspaceAnalysis/pyvrep/scenes/lua/createRobot.lua:59>
Error: [string -unknown location]:?: Call failed. (simCallScriptFunctionEx on createJointEx@remoteApiCommandServer)
However, if I call vrep.simxGetLastErrors() from python the returned value is:
['Object does not exist. (simGetObjectHandle)', 'Error in script function. (simCallScriptFunctionEx)']

The error is technically correct, but not very useful for debugging compared to the stack trace.

I've also tried looked into looking at the terminal output of the process that was used to launch vrep.sh, but the stack trace is not printed there.

Is is possible to get the stack trace through the external API or terminal stdout?

Thanks

coppelia
Site Admin
Posts: 7124
Joined: 14 Dec 2012, 00:25

Re: How to access the stack trace from the external API

Post by coppelia » 08 Mar 2019, 13:13

hum... maybe one of following 2 methods?

Code: Select all

function test3(n)
    local a=sim.getObjectHandle(n)
    return a,"hello"
end

function test2(n)
    return test3(n)
end

function test1(n)
    return test2(n)
end

function sysCall_init()
    local method1=true
    local objectName='notExistingObject'
    if method1 then
        local co=coroutine.create(test1)
        local result,retArg1,retArg2=coroutine.resume(co,objectName)
        print(result,retArg1,retArg2)
        print(debug.traceback(co))
    else
        local result,retArg1,retArg2=xpcall(function() return test1(objectName) end, debug.traceback)
        print(result,retArg1,retArg2)
        print(debug.traceback())
    end
end
Cheers

agsdyson
Posts: 30
Joined: 13 Feb 2019, 14:02

Re: How to access the stack trace from the external API

Post by agsdyson » 14 Mar 2019, 16:57

Thanks. I've been playing around with those functions, but the debug.traceback() does not seem to have as much information as the stack trace in the status area.

coppelia
Site Admin
Posts: 7124
Joined: 14 Dec 2012, 00:25

Re: How to access the stack trace from the external API

Post by coppelia » 18 Mar 2019, 15:07

In V-REP V3.6.1 rev1, available within one day, you can use: sim.getStackTraceback

Cheers

agsdyson
Posts: 30
Joined: 13 Feb 2019, 14:02

Re: How to access the stack trace from the external API

Post by agsdyson » 19 Mar 2019, 16:36

Thank you, this will be very helpful for debugging.

Post Reply