dasch-swiss/sipi

Lua function SipiImage:write seems to modify its input variable if there's an error

benjamingeer opened this issue · 3 comments

In PR dasch-swiss/dsp-api#1191, Knora's script upload.lua is trying to save a SipiImage:

https://github.com/dhlab-basel/Knora/blob/b5f946da134311d5f966117ad91a359cfa07164b/sipi/scripts/upload.lua#L139

local jp2_file_path = config.imgroot .. '/tmp/' .. hashed_jp2_filename
local success, error_msg = uploaded_image:write(jp2_file_path)

if not success then
    send_error(500, "Unable to write " .. tostring(jp2_file_path) .. ": " .. tostring(error_msg))
return

This works on my local machine, but on Travis it fails in a very strange way:

https://travis-ci.org/dhlab-basel/Knora/jobs/486906660

{
    "message": "Unable to write false: false"
}

As you can see, jp2_file_path has a boolean value, but I don't see how this is possible, because it was just given a string value. Could uploaded_image:write be modifying the value of jp2_file_path by mistake?

In order to figure out why the script is failing on Travis, I need the real error message from uploaded_image:write.

Ivan managed to get Sipi's log output, so we can see that the real error is:

Unable to open output file, "/sipi/images/tmp/U/K9MibG9Qexk-BePia5nc6vC.jp2".

This is because /sipi/images/tmp wasn't created.

I added a test for this in #282.

Should be fixed. Added following test code to read_write_lua.lua for testing:

-- the following write must fail
outfilename = '/gaga/gaga.jpx'
success, error = img:write(outfilename)
if outfilename ~= '/gaga/gaga.jpx' then
    server.log("failing SipiImage.write() changed input parameter ", server.loglevel.LOG_ERR)
    send_error(500, "failing SipiImage.write() changed input parameter: ")
    return
end
``