Copy link to clipboard
Copied
I have a function being called in a context, itself within an async task. If the function generates an error it seems to do so silently and the task is killed. Does anyone have a way to catch this?
More specifically, I"m calling Jeffrey Friedl's JSON:decode( string ) from inside the task. If string isn't valid, decode barfs, the task is killed and I can't take action to deal with it:
LrTasks.startAsyncTask( function()
LrFunctionContext.callWithContext( 'socket_remote', function( context )
local tab = JSON:decode( string ) -- never gets here if string is invalid JSON if tab == nil then -- address the error end end end
Thoughts appreciated.
Copy link to clipboard
Copied
sorry, dodgy code layout
LrTasks.startAsyncTask( function() LrFunctionContext.callWithContext( 'socket_remote', function( context ) local tab = JSON:decode( string ) -- never gets here if string is invalid JSON if tab == nil then -- address the error end end end
Copy link to clipboard
Copied
OK. Debug Toolkit. Thanks John. Again.
Copy link to clipboard
Copied
It's one of those things that Adobe got horribly wrong early on. It would be trivial to have a default error handler for LR tasks. But Adobe has put almost no effort into the SDK in the last many years, unfortunately.
Copy link to clipboard
Copied
Out of curiosity, is there no way at all to trap an error inside a task?
Copy link to clipboard
Copied
You can trap errors with pcall(). If you want the error to display an error dialog and then terminate the task after the dialog is dismissed, use LrDialogs.attachErrorDialogToFunctionContext().
The Debugging Toolkit's Debug.showErrors() uses the latter:
--[[----------------------------------------------------------------------------
showErrors (func)
Returns a function wrapped around "func" such that if any errors occur from
calling "func", the standard Lightroom error dialog is displayed. By
default, Lightroom doesn't show an error dialog for callbacks from LrView
controls or for tasks created by LrTasks.
------------------------------------------------------------------------------]]
function showErrors (func)
return function (...)
return LrFunctionContext.callWithContext("wrapped",
function (context)
LrDialogs.attachErrorDialogToFunctionContext (context)
return func (unpack (arg))
end)
end
end