Script aborts when accessing item.imgDate
I have a script that I have been using for quite some years now. It checks whether the item has an item.imgDate - if so use that for renaming, otherwise it uses the item.modifiedDate. So far so good.
Somehow since I have a new phone there are sometimes images, that make the script crash. It will simply abort processing without any further notice. The issue appears between the log messages "a" and "b" and the catch is not triggered.
This is really annoying, since I have to remove all the trouble files from the list for the script to work. Any ideas, what's going wrong.
Here is the script:
----------------------------------------
if(item == null)
{
console.log(" -> something went wrong: item is null");
return "fehler";
}
console.log(index + ": " + item.filename);
//item.ext = item.ext.toLowerCase();
// select date according depending on whether it is an image or not
var date;
try
{
console.log("a");
console.log(index + ": " + item.imgDate);
console.log("b");
}
catch(e)
{
console.log(" -> something went wrong: cannot access imgDate");
}
if((item.imgDate != null) && (item.imgDate.getTime() > 0)) // only images will have a valid date
{
console.log(" -> using imgDate = " + item.imgDate);
date = item.imgDate;
}
else
{
console.log(" -> using modifiedDate = " + item.modifiedDate);
date = item.modifiedDate;
}
if(date == null)
{
console.log(" -> something went wrong: date is null");
return item.filename;
}
// helper function
var fill = function(str, len) {
var s = "" + str;
while(s.length < len)
s = "0" + s;
return s;
};
if(offset)
{
date.setFullYear( date.getFullYear() + offset_year);
date.setMonth( date.getMonth() + offset_month);
date.setDate( date.getDate() + offset_date);
date.setHours( date.getHours() + offset_hour);
date.setMinutes( date.getMinutes() + offset_minute);
date.setSeconds( date.getSeconds() + offset_second);
}
// format the date
var dateStr = (date.getFullYear())
+ "." + fill(date.getMonth() + 1,2)
+ "." + fill(date.getDate(),2)
+ " " + fill(date.getHours(),2)
+ "." + fill(date.getMinutes(),2)
+ "." + fill(date.getSeconds(),2);
console.log(" -> adjusted date = " + dateStr);
return dateStr;
Somehow since I have a new phone there are sometimes images, that make the script crash. It will simply abort processing without any further notice. The issue appears between the log messages "a" and "b" and the catch is not triggered.
This is really annoying, since I have to remove all the trouble files from the list for the script to work. Any ideas, what's going wrong.
Here is the script:
----------------------------------------
if(item == null)
{
console.log(" -> something went wrong: item is null");
return "fehler";
}
console.log(index + ": " + item.filename);
//item.ext = item.ext.toLowerCase();
// select date according depending on whether it is an image or not
var date;
try
{
console.log("a");
console.log(index + ": " + item.imgDate);
console.log("b");
}
catch(e)
{
console.log(" -> something went wrong: cannot access imgDate");
}
if((item.imgDate != null) && (item.imgDate.getTime() > 0)) // only images will have a valid date
{
console.log(" -> using imgDate = " + item.imgDate);
date = item.imgDate;
}
else
{
console.log(" -> using modifiedDate = " + item.modifiedDate);
date = item.modifiedDate;
}
if(date == null)
{
console.log(" -> something went wrong: date is null");
return item.filename;
}
// helper function
var fill = function(str, len) {
var s = "" + str;
while(s.length < len)
s = "0" + s;
return s;
};
if(offset)
{
date.setFullYear( date.getFullYear() + offset_year);
date.setMonth( date.getMonth() + offset_month);
date.setDate( date.getDate() + offset_date);
date.setHours( date.getHours() + offset_hour);
date.setMinutes( date.getMinutes() + offset_minute);
date.setSeconds( date.getSeconds() + offset_second);
}
// format the date
var dateStr = (date.getFullYear())
+ "." + fill(date.getMonth() + 1,2)
+ "." + fill(date.getDate(),2)
+ " " + fill(date.getHours(),2)
+ "." + fill(date.getMinutes(),2)
+ "." + fill(date.getSeconds(),2);
console.log(" -> adjusted date = " + dateStr);
return dateStr;