• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Errors in button actions and observer functions don't display dialogs?

LEGEND ,
Jun 13, 2010 Jun 13, 2010

Copy link to clipboard

Copied

In LR 3 SDK, it appears that errors don't display the error dialog if they occur in button-action functions or observer functions invoked as the result of some user action on a control. This makes debugging quite tedious.  I have a solution, but it seems heavy handed and I'm wondering if I'm missing something simple?

For example, in Sample Plugins\helloworld.lrdevplugin\CustomDialogWithObserver.lua, modify "myCalledFunction" to raise an error:

    local function myCalledFunction()
        outputToLog( "props.myObservedString has been updated." )
        error "Example of an internal error"

The error will cause the observer function to terminate immediately without displaying the error dialog.

My heavy-handed solution is to wrap all button and observer functions with LrFunctionContext.callWithContext() and use LrDialogs.attachErrorDialogToFuntionContext.  To make that easy, I use this utility function to wrap any function with callWithContext():

local function showErrors (func)
    return function (...)
        LrFunctionContext.callWithContext("wrapped",
            function (context)
                LrDialogs.attachErrorDialogToFunctionContext (context)
                func (unpack (arg))
                end)
        end
    end

For example, here's how to wrap the action function of a button:

     viewFactory:push_button {title = "Search", action = showErrors (searchPush)}

Is there an easier way, e.g. some call or configuration setting I've missed?

TOPICS
SDK

Views

772

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 ,
Jun 13, 2010 Jun 13, 2010

Copy link to clipboard

Copied

The same issue also occurs for validate functions of controls.

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 ,
Jun 13, 2010 Jun 13, 2010

Copy link to clipboard

Copied

This was the case in 2.0 as well. One work-around is to wrap the function context at the outermost level. For example, if you wrap the entire "sectionsForTopOfDialog" function in a context, then you don't have to worry about various called functions... - this is what I just started doing, but I confess I haven't specifically checked whether the context is inherited by called functions as well - maybe you can tell me/us.

I'm not sure why these functions don't just have a default context, like the export functions do...

Rob

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 ,
Jun 13, 2010 Jun 13, 2010

Copy link to clipboard

Copied

One work-around is to wrap the function context at the outermost level. For example, if you wrap the entire "sectionsForTopOfDialog" function in a context, then you don't have to worry about various called functions... - this is what I just started doing, but I confess I haven't specifically checked whether the context is inherited by called functions as well - maybe you can tell me/us.

In the "helloworld" sample plugin, the custom dialog defined in CustomDialogWithObserver.lua already wraps the entire creation of the dialog with callWithContext() (it needs to do that so it can create an observable property table).  But that doesn't have any effect on the callback functions for observers, control actions, and validate functions.  In that example, is there any other way to wrap "everything"?

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 ,
Jun 15, 2010 Jun 15, 2010

Copy link to clipboard

Copied

LATEST

Hi John,

I've noticed the same thing - and I had a similar issue with the "catalog:withWriteAccessDo" function (operates in a separate task). The button handlers and such don't seem to inherit context.

I don't know a way around other than wrapping each one individually - maybe Eric Scouten or one of the other SDK gurus will enlighten us.

Rob

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