• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
0

errors inside async tasks

Engaged ,
Sep 27, 2018 Sep 27, 2018

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.

TOPICS
SDK

Views

700

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 27, 2018 Sep 27, 2018

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  

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 27, 2018 Sep 27, 2018

Copy link to clipboard

Copied

OK. Debug Toolkit. Thanks John. Again.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 27, 2018 Sep 27, 2018

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 27, 2018 Sep 27, 2018

Copy link to clipboard

Copied

Out of curiosity, is there no way at all to trap an error  inside a task?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 27, 2018 Sep 27, 2018

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines