3 Replies Latest reply on Mar 19, 2017 7:23 PM by johnrellis

    Where did my assert go?

    raymanningphotography Level 1

      I'm having problems with error dialogs inside of event handlers (excuse me if that's not the vernacular used for LUA/LR). The code below opens a dialog with a single button which causes an assert(false) condition. Inside the handler, there is no error message box displayed. Outside the handler, an error message is displayed. I've tried calling LrDialogs.attachErrorDialogToFunctionContext with no change and I also tried wrapping showCustomDialog and the anonymous action with John R. Ellis's showErrors and still do not get an error message.

       

      What am I missing?

       

       

       

      -- required imports

      local LrDialogs = import "LrDialogs"

      local LrTasks = import "LrTasks"

      local LrView = import "LrView"

      local LrFunctionContext = import "LrFunctionContext"

       

      local function showCustomDialog()

       

        LrFunctionContext.callWithContext(

        "showCustomDialog",

        function( context )

       

        -- This assert will show a dialog

        -- assert(false,"false assertion")

       

        local viewFactory = LrView.osFactory()

        local content = viewFactory:push_button

        {

        title = "Push Me",

        action = function()

        -- this does not show a dialog

        assert(false,"false assertion")

        end

        }

       

       

        LrDialogs.presentFloatingDialog(

        _PLUGIN,

        {

        title = "My Dialog",

        contents = content,

        }

        )

       

        end)

      end

       

      LrTasks.startAsyncTask(showCustomDialog)

        • 1. Re: Where did my assert go?
          johnrellis Most Valuable Participant

          When I wrap the functions passed to the SDK with Debug.showErrors(), the assertion error is trapped by Debug:

           

          local Require = require 'Require'.path ("../common").reload ()
          local Debug = require 'Debug'.init ()
          require 'strict'
          
          local LrDialogs = import "LrDialogs"
          local LrFunctionContext = import "LrFunctionContext"
          local LrTasks = import "LrTasks"
          local LrView = import "LrView"
          
          local showErrors = Debug.showErrors
          
          local function showCustomDialog()
              LrFunctionContext.callWithContext ("showCustomDialog", 
              showErrors (function( context )
                  local viewFactory = LrView.osFactory()
                  local content = viewFactory:push_button {title = "Push Me",
                      action = showErrors (function()
                          assert (false, "false assertion")
                          end)}
                  LrDialogs.presentFloatingDialog (_PLUGIN, {title = "My Dialog",
                      contents = content})
                  end))
              end
          
          LrTasks.startAsyncTask (showErrors (showCustomDialog))
          

           

          I'm using the most recent version of the debugging toolkit, but I'm sure that the old version would also trap the error.

          • 2. Re: Where did my assert go?
            raymanningphotography Level 1

            Thanks John!  I'm not exactly sure what was happening. I'm not able to reproduce what I saw (or I think I saw). I also started hitting an error that closeWindow was being called on a nil window. A restart of lightroom seems to have corrected that.

            • 3. Re: Where did my assert go?
              johnrellis Most Valuable Participant

              I've found restarting LR and going to bed often solves mysterious LR problems...