9 Replies Latest reply on Nov 4, 2012 7:18 PM by DawMatt

    LUA Failure Output?

    PaulWaldo

      I'm wondering how to determine why my script is failing. All I get is the dreaded "Unknown error" when my export script is called.  I'm sure it is a syntax error or something like that, but there is no output.  Maybe I missed it in the docs, but is there a way to see the output of running the script?  I do have logger statements, but that doesn't help for a syntax error :-(  Thanks!

        • 1. Re: LUA Failure Output?
          johnrellis Most Valuable Participant

          You might check out the Debugging Toolkit for LR.  It takes some time to hook it up initially, but it can greatly speed up the diagnosis of all those annoying Lua gotchas.

          • 2. Re: LUA Failure Output?
            PaulWaldo Level 1

            This looks very cool, John! 

             

            I'm having a problem getting the debugging functionality to work.  I have followed the instructions for my Export Plugin and added

            exitStatus = LrTasks.execute(Debug.showErrors (quotedCommand))

            to my export function.  This apparently has a problem, as execution just stops.

             

            I'd love to be able to see an error message that the Lua interpreter spits out!  This is what I was originally hoping for.  Any ideas?  Thanks!

            • 3. Re: LUA Failure Output?
              johnrellis Most Valuable Participant

              The statement  you wrote:

               

              exitStatus = LrTasks.execute(Debug.showErrors (quotedCommand))

               

              won't work, since Debug.showErrors takes a function as an argument, wraps it with the debugger, and returns a function.  In the expression above, you're passing it a string (quotedCommand).

               

              In the documentation with the toolkit, "Debugging Toolkit.htm", see the section "Debugging Export- and Publish-Service Plugins" for a step-by-step recipe for hooking up the debugger. 

              1 person found this helpful
              • 4. Re: LUA Failure Output?
                DawMatt Level 3

                John's debugging toolkit is probably a good idea to adopt early in your Lightroom plugin development lifecycle. In the long run it will save you a lot of effort coming up with your own approach to tracking down errors or even just trying to understand what is going on.

                 

                The alternate approach for tracking down this type of error would be checking the Plug-in Manager dialog entry for your plugin, scrolling to the bottom and opening the "Plug-in Author Tools" panel. If the plugin is experiencing a syntax error there will often be a message displayed here, and if you save the diagnostics ("Save Diagnostic Log to File") the log messages should give you some hint what is going on.

                 

                To minimise the chances of experiencing a Lua syntax error I'd consider using an IDE that understands Lua. My personal favourite is IntelliJ, with the Lua plugin installed. But it isn't the only option out there.

                 

                Matt

                • 5. Re: LUA Failure Output?
                  PaulWaldo Level 1

                  Thanks for the reply, Matt.  I've been able to debug syntax errors via the plugin manager dialog, but the problems I'm currently experiencing are runtime problems.  If lua detects a runtime problem, it aborts the execution of the script, but the diagnostic messages just go into the ether.  Is there any way to see those?

                  • 6. Re: LUA Failure Output?
                    johnrellis Most Valuable Participant

                    Paul wrote:

                    If lua detects a runtime problem, it aborts the execution of the script, but the diagnostic messages just go into the ether.

                    In general, all functions passed to LR SDK APIs, including the main functions of tasks, need to have the following at the top level of their body:

                     

                    LrFunctionContext.callWithContext ("myfunction",  function (context)
                         LrDialogs.attachErrorDialogToFunctionContext (context)
                         ...main  body of the function...
                         end)
                    

                     

                    Doing this will ensure that LR will display Lua errors in a popup window.  The Debugging Toolkit makes this easy via its Debug.showErrors() function.

                    • 7. Re: LUA Failure Output?
                      PaulWaldo Level 1

                      Worked like a charm, John.  I'm still trying to wrap my head around the debugging toolkit.  What is the best place to ask questions specific to the toolkit?  Here or elsewhere?  Thanks!

                      • 8. Re: LUA Failure Output?
                        johnrellis Most Valuable Participant

                        It does take some time to get the toolkit hooked up -- Adobe just put in much effort into plugin debugging.  (Lua itself has quite reasonable debugging hooks.)

                         

                        Ask your questions here, in case anyone else has similar questions in the future.

                        • 9. Re: LUA Failure Output?
                          DawMatt Level 3

                          PaulWaldo wrote:

                           

                          If lua detects a runtime problem, it aborts the execution of the script, but the diagnostic messages just go into the ether.  Is there any way to see those?

                          If you are running on a Windows system, try installing DebugView and using it to watch the Windows debug log. Major issues with Lightroom plugins (e.g. throwing an exception) tend to get displayed in the debug log, and you can use LrLogger to write messages here as well. You might need to use the program's filters to hide some of the less interesting log messages being generated by your system though.

                           

                          On Mac the console app can show you similar information.

                           

                          These can be useful extra sources of information. Hopefully the debugging toolkit should cover most of your debugging needs once you get it installed and working.

                           

                          Matt