novoid/Memacs

Invalid year in filename - Traceback

bdillahu opened this issue · 7 comments

I have a photograph that had incorrect exif data... so when it got renamed (via exiftool), it got an improbably year:

1899-12-30T00.00.00_P1000286.jpg_original

Now, I know the obvious is to fix the file, and I will, but I wanted to point out that it does cause an error and kills memacs_filenametimestamps.py.

Traceback below... My suggestion would be to just skip a file like that (as you do files without a date in the filename), but not sure if that's the best approach.

If you agree, I'll attempt to brush off my python and try to do a PR, but if nothing else, thought I would let you know.

Traceback (most recent call last):
File "/home/bdillahu/memacs/lib/python2.7/site-packages/memacs/lib/memacs.py", line 187, in handle_main
self._main()
File "/home/bdillahu/memacs/lib/python2.7/site-packages/memacs/filenametimestamps.py", line 194, in _main
self.__handle_folder(folder)
File "/home/bdillahu/memacs/lib/python2.7/site-packages/memacs/filenametimestamps.py", line 107, in __handle_folder
self.__handle_file(file, rootdir)
File "/home/bdillahu/memacs/lib/python2.7/site-packages/memacs/filenametimestamps.py", line 185, in __handle_file
self.__parse_file(file, link)
File "/home/bdillahu/memacs/lib/python2.7/site-packages/memacs/filenametimestamps.py", line 120, in __parse_file
orgdate = OrgFormat.strdatetimeiso8601(timestamp)
File "/home/bdillahu/memacs/lib/python2.7/site-packages/memacs/lib/orgformat.py", line 263, in strdatetimeiso8601
return OrgFormat.date(tuple_date, show_time=True)
File "/home/bdillahu/memacs/lib/python2.7/site-packages/memacs/lib/orgformat.py", line 134, in date
return time.strftime("<%Y-%m-%d %a %H:%M>", local_structtime)
ValueError: year out of range
Traceback (most recent call last):
File "bin/memacs_filenametimestamps.py", line 39, in
memacs.handle_main()
File "/home/bdillahu/memacs/lib/python2.7/site-packages/memacs/lib/memacs.py", line 187, in handle_main
self._main()
File "/home/bdillahu/memacs/lib/python2.7/site-packages/memacs/filenametimestamps.py", line 194, in _main
self.__handle_folder(folder)
File "/home/bdillahu/memacs/lib/python2.7/site-packages/memacs/filenametimestamps.py", line 107, in __handle_folder
self.__handle_file(file, rootdir)
File "/home/bdillahu/memacs/lib/python2.7/site-packages/memacs/filenametimestamps.py", line 185, in __handle_file
self.__parse_file(file, link)
File "/home/bdillahu/memacs/lib/python2.7/site-packages/memacs/filenametimestamps.py", line 120, in __parse_file
orgdate = OrgFormat.strdatetimeiso8601(timestamp)
File "/home/bdillahu/memacs/lib/python2.7/site-packages/memacs/lib/orgformat.py", line 263, in strdatetimeiso8601
return OrgFormat.date(tuple_date, show_time=True)
File "/home/bdillahu/memacs/lib/python2.7/site-packages/memacs/lib/orgformat.py", line 134, in date
return time.strftime("<%Y-%m-%d %a %H:%M>", local_structtime)
ValueError: year out of range

Thanks for reporting the issue!

Did I understand you correctly: an exception is thrown and the file still gets renamed with a wrong date-stamp?

IMO, catching the exception and writing a human-readable error message to stdout without renaming would be my choice.

Sorry, I wasn't clear... the rename was a prior job using an exiftool based script that renamed the file based on EXIF data - given the data was bad, the file was renamed with an "out of range" date (1899).

I wasn't using memacs code to do the rename, just running the index job, which dies when it hits the early date.

Ideally (to me) any valid calendar date would work, but I haven't delved into the code to try to determine what library is getting used and what the limitations are.

Excuse me - I obviously mixed up two of my projects https://github.com/novoid/date2name (for renaming) and this Memacs module 🤦

I'll add exception handling as suggested.

Your issue does not seem urgent (no need for a quickfix) I guess. Report back if this is not the case.

Therefore, the change will take some time because "orgformat.py" have to be moved to an independent library package because it is used in several projects already. Unfortunately, due to partly migration from Python 2 to 3, the versions have diverged. Therefore, I have to merge them beforehand.

Thanks for reporting the issue in any case!

No problem, and certainly no urgency... just figured I would report it since I ran into it.

Hi,

I just merged the different orgformat.py versions and tried to reconstruct your issue.

Fortunately or unfortunately, I could not find any issue related to this year you were using (see commit above).

Could it be the case that the issue is not any more on your side as well?
If so: what versions are you using? (OS and Python)

Please do report back. Otherwise, I'll close this issue in a couple of months.

Thanks for helping!

Thanks for taking a look... had a chance to re-test and, like you, I can't recreate the issue with current release/github code. So I guess something fixed it along the way :-)

I would say close it and I'll report again if I manage to recreate it in the future.

OK, so I assume this got "fixed" by porting the thing to Python 3.
Thanks for reporting anyhow!