I have the following code to transfer metadata from one image to another:
local sts, val = LrTasks.pcall( fromPhoto.getFormattedMetadata, fromPhoto, k )
if sts then
sts, msg = LrTasks.pcall( toPhoto.setRawMetadata, toPhoto, k, val ) -- this pcall does not seem to work - error caught
-- in calling context for some reason.
if not sts then
RcUtils.logError( LOC( "$$$/X=Unable to set raw metadata using '^1' as key and '^2' as value, error message: ^3", k, val, msg ) )
RcUtils.logError( LOC( "$$$/X=Unable to get formatted metadata using '^1' as key, error message: ^2", k, val ) )
get-formatted-metadata errors are trapped by the pcall, but set-raw-metadata errors are not (they always propagate to the calling context).
Have you tried using the Lua pcall() rather than LrTasks.pcall()? The documentation of LrTasks.pcall says:
Simulates Lua's standard
pcall(), but in a way that allows a call to
LrTasks.yield() to occur inside it.
but in what actual instances would it be desirable to use one version of the other? I'm wondering in your case if there s some subtlety (or LR bug) caused by an attempt of setRawMetadata() to call yield()?
If pcall() doesn't catch the error, you might try LrFunctionContext.callWithContext() with a context:addCleanUpHandler() -- that seems to catch everything.