4 Replies Latest reply on Mar 9, 2017 12:19 AM by kimaldis

    Better error dialog

    kimaldis Level 1

      I'm finding I need a little more in a dialog than I can get from the standard error dialog that comes with error(). Is there a that I can  use a more customised one to use in its place?

       

      thanks

        • 1. Re: Better error dialog
          johnrellis Most Valuable Participant

          You can use LrTasks.pcall() to catch the error and then use LrDialogs.presentModalDialog() to show your custom dialog.   But you'll have to do that for your main function and every function that is passed as a callback to the SDK (e.g. passed to LrTasks, to LrView, etc.).

           

          You can define a function showErrors() that makes that easier by wrapping its argument function with the pcall() and invocation of your custom dialog:

           

          local function showErrors (f)
              return function (...)
                  local success, result = LrTasks.pcall (function () return f (...) end)
                  if not success then 
                      LrDialogs.presentModalDialog (...dialog...)
                  else
                      return result
                      end
                  end
              end
          

           

          You'd use it like this:

           

          LrTasks.startAsyncTask (showErrors (myFunction))
          
          f:edit_field {validate = showErrors (myValidateFunction)...}
          

           

          (I haven't tested the particular code above, but it's similar to what my Debugging Toolkit does.)

          • 2. Re: Better error dialog
            kimaldis Level 1

            Normally yes but in this instance I'm catching errors in publishServiceProvider.reparentPublishedCollection. I need to call error() to prevent Lightroom from doing the reparent.

            • 3. Re: Better error dialog
              johnrellis Most Valuable Participant

              I'm catching errors in publishServiceProvider.reparentPublishedCollection. I need to call error() to prevent Lightroom from doing the reparent.

              Two thoughts:

               

              1. Unfortunately, the documentation about error handling is vague and ambiguous.  reparentPublishedCollection() says:

               

              ... If your plug-in is unable to update the remote service for any reason, you should throw a Lua error from this function via error() or a related built-in function. This causes Lightroom to present a dialog asking the user whether to revert the change, or proceed with the change locally while informing the user this will leave the equivalent collection unaltered on the remote service.

               

              This implies to me that if reparentPublishedCollection() throws an error, the standard error dialog won't be shown.  When a user tries to reparent a published collection, are you seeing the standard error dialog or the the one described in the documentation above?

               

              2. You might check out LrErrors.throwCanceled(), whose documentation seems to imply it should be used precisely for exceptional termination rather than indicating programming errors (two overlapping concepts that Lua and LR conflate). 

               

              3. Check out LrErrors.throwUserError() -- this lets you specify the precise text shown in the error dialog presented by LR.  (See page 19 of the SDK Guide.)

              • 4. Re: Better error dialog
                kimaldis Level 1

                Sorry for the delay, John.

                 

                So, error() definitely presents a dialog.

                 

                throwUserError() seems to do much the same as error()

                 

                throwCanceled() does the job, terminating quietly, cancelling the parenting; no dialog. So I can present my own dialog prior to calling this.

                 

                Many thanks for your time.