10 Replies Latest reply on Sep 19, 2010 2:41 PM by areohbee

    Bad argument #1 to 'concat' (table contains non-strings)

    dtauzell

      I have an export plugin that worked under Lightroom 2.0.  Now, under 3.0 I sometimes get this error (it seems to be itermitent):

       

      Bad argument #1 to 'concat' (table contains non-strings)

       

      Has anybody seen this?  Is there some way to get a stack trace to see exactly where this is coming from?   How do you debug these types of problems?

       

      Thanks,

          Dave

       

      (I can post code if need be, but I'm not even sure which part of the code is causing this)

        • 1. Re: Bad argument #1 to 'concat' (table contains non-strings)
          areohbee Level 5

          I've not seen it just due to the Lr version. But one way to debug is to do a global replace of table.concat with MyDebugTable.concat then put some debug logic in MyDebugTable.concat.

           

          I assume it is a table in your plugin, as opposed to some table in Lightroom proper, eh?

           

          Rob

          • 2. Re: Bad argument #1 to 'concat' (table contains non-strings)
            dtauzell Level 1

            I don't actually have any calls to "concat" in my code. Does anybody know of any way to produce a stacktrace that shows where this error is coming from?  Right now I just get a dialog box with the error message.

            • 4. Re: Bad argument #1 to 'concat' (table contains non-strings)
              johnrellis Most Valuable Participant

              Debugging plugins is especially primitive.  Unless someone else knows any magic that I've missed, there doesn't seem to be any way to get a stack traceback.  You'll have to insert debugging print statements using the LrLogger facilities and do binary search to narrow down where the error is occurring.

               

              Note that it is possible to get a stack trace, but only of the current task and only by calling debug.getinfo() directly.  For example, I have a utility function stackTrace() (see below) that prints a stack trace to the log.  But there is no way to get stackTrace() invoked when an error occurs.  If you try to invoke it from an LrFunctionContext.addCleanupHandler(), all of the useful stack context has already been popped from the stack.

               

              --[[----------------------------------------------------------------------------
              void stackTrace ()

               

              Prints to the log a rudimentary stack trace (function name, source file, line
              number).
              ------------------------------------------------------------------------------]]

               

              function stackTrace ()
                  log:trace ("Stack trace:")
                  local i = 2
                  while true do
                      local info = debug.getinfo (i)
                      if not info then break end
                      log:tracef ("%s [%s %s]", info.name, info.source, info.currentline)
                      i = i + 1
                      end
                  end
                    

              • 5. Re: Bad argument #1 to 'concat' (table contains non-strings)
                dtauzell Level 1

                I haven't tried your stacktrace code yet ... but I did put in more debug items and it seem to fail with a call to LrHttp.postMultipart.  This is where I am actually posting a file to a web server.  Here is a snipped of the code:

                 

                LrDialogs.message("up1")

                        local albumName = assert( params.albumName )

                        local theFilePath = assert( params.filePath )

                        params.filePath = nil

                 

                        LrDialogs.message("up2")

                        local theFileName = LrPathUtils.leafName( theFilePath )

                        local mimeChunks = {}

                 

                 

                        mimeChunks[ #mimeChunks + 1 ] = { name = 'pix_api_token', value = params.api_token }

                        mimeChunks[ #mimeChunks + 1 ] = { name = 'set_albumName', value = albumName }

                        mimeChunks[ #mimeChunks + 1 ] = {       name = 'SourceFile',

                                                                fileName = theFileName,

                                                                filePath = theFilePath,

                                                                contentType = 'application/octet-stream'

                                                        }

                 

                        -- Post it and wait for confirmation.

                        LrDialogs.message("up3")

                        local result = LrHttp.postMultipart( postUrl, mimeChunks )

                        LrDialogs.message("up4")

                 

                 

                It fails after up3 and before up4. It is failing when I try and export a raw photo as a jpeg. 

                 

                -Dave

                • 6. Re: Bad argument #1 to 'concat' (table contains non-strings)
                  johnrellis Most Valuable Participant

                  Have you verified that mimeChunks contains only strings or integers, which is required by table.concat?  You could use my dump() utility function to quickly print out the entire contents of the table recursively:

                   

                  --[[----------------------------------------------------------------------------
                  dump (label, x)

                  Dumps the value of "x" to the log, recursively dumping tables (and detecting
                  loops) with proper indenting.
                  ------------------------------------------------------------------------------]]

                   

                  function dump (label, x)
                      local function dump1 (x, indent, visited)
                          if type (x) ~= "table" then
                              log:trace (string.rep (" ", indent) .. tostring (x))
                              return
                              end

                          visited [x] = true
                          if indent == 0 then
                              log:trace (string.rep (" ", indent) .. tostring (x))
                              end
                          for k, v in pairs (x) do   
                              log:trace (string.rep (" ", indent + 4) .. tostring (k) .. " = " ..
                                         tostring (v))
                              if type (v) == "table" and not visited [v] then
                                  dump1 (v, indent + 4, visited)
                                  end
                              end
                          end
                         
                      log:trace (label .. ":")
                      dump1 (x, 0, {})
                      end

                  • 7. Re: Bad argument #1 to 'concat' (table contains non-strings)
                    areohbee Level 5

                    Another hot tip from John (The Man) Ellis! (stack-trace)

                     

                    I can't believe I've been debugging all this time without using the lua 'debug' object.

                     

                    PS - the "logamous-anythingamous" function is awesome too!!!

                     

                    Thanks,

                    Rob

                    • 8. Re: Bad argument #1 to 'concat' (table contains non-strings)
                      johnrellis Most Valuable Participant

                      Unfortunately, stackTrace() can't be used to get a trace once an error has occurred.  I've only found it useful to call it right before where I know the error is occurring, so at least I know the sequence of calls that got me there.

                      • 9. Re: Bad argument #1 to 'concat' (table contains non-strings)
                        areohbee Level 5

                        I see - makes sense, I think. - The stack has already been "unwound" by the time an error is detectable by the plugin, I guess.

                         

                        Still useful though...

                         

                        Cheers,

                        Rob

                        • 10. Re: Bad argument #1 to 'concat' (table contains non-strings)
                          johnrellis Most Valuable Participant
                          The stack has already been "unwound" by the time an error is detectable by the plugin,

                           

                          Right.  If you try something like:

                           

                          LrFunctionContext.callWithContext ("name", function (context)

                              context:addFailureHandler (function ()

                                  stackTrace ()

                                  end)

                              ...your code that raises an error...

                           

                          by the time the failure handler is invoked, the stack appears to have been unwound to that point.