jmathai / elodie

An EXIF-based photo assistant, organizer and workflow automation tool.
https://bit.ly/introducing-elodie
Apache License 2.0
1.27k stars 139 forks source link

set_album_from_folder assumes metadata dict is not None #98

Closed Ramblurr closed 8 years ago

Ramblurr commented 8 years ago

The set_album_from_folder(self): function assumes that the metadata dict will not be None, but in fact it can be None, if the underlying metadata reader fails.

I'm not sure while it's failing yet on a certain file, but it is, and it is causing a crash here.

Traceback (most recent call last):
  File "/home/ramblurr/src/elodie/elodie.py", line 228, in <module>
    main()
  File "/home/ramblurr/src/elodie/.py/lib/python2.7/site-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/home/ramblurr/src/elodie/.py/lib/python2.7/site-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/home/ramblurr/src/elodie/.py/lib/python2.7/site-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/ramblurr/src/elodie/.py/lib/python2.7/site-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/ramblurr/src/elodie/.py/lib/python2.7/site-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/home/ramblurr/src/elodie/elodie.py", line 94, in _import
    trash)
  File "/home/ramblurr/src/elodie/elodie.py", line 52, in import_file
    media.set_album_from_folder()
  File "/home/ramblurr/src/elodie/elodie/media/media.py", line 260, in set_album_from_folder
    if(metadata['album'] is not None):
TypeError: 'NoneType' object has no attribute '__getitem__'
Ramblurr commented 8 years ago

The offending file was a 0 byte file with a JPG extension.

Also, returning False from the set_album_from_folder function when metadata is None, prevents the crash and continues processing other files.

jmathai commented 8 years ago

Thanks @Ramblurr. Let me spend some time thinking about how we might want to handle this.

ldexterldesign commented 8 years ago

Hey,

No "0 byte files" in my case, but I have the same issue:

Traceback (most recent call last):
  File "./elodie.py", line 230, in <module>
    main()
  File "/Library/Python/2.7/site-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/Library/Python/2.7/site-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Library/Python/2.7/site-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Library/Python/2.7/site-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "./elodie.py", line 96, in _import
    trash)
  File "./elodie.py", line 57, in import_file
    media, allowDuplicate=False, move=False)
  File "/Applications/elodie/elodie/filesystem.py", line 182, in process_file
    metadata = media.get_metadata()
  File "/Applications/elodie/elodie/media/text.py", line 71, in get_metadata
    return super(Text, self).get_metadata()
  File "/Applications/elodie/elodie/media/base.py", line 80, in get_metadata
    'date_taken': self.get_date_taken(),
  File "/Applications/elodie/elodie/media/text.py", line 58, in get_date_taken
    if self.metadata_line and 'date_taken' in self.metadata_line:
TypeError: argument of type 'int' is not iterable

Do we know how to avoid this issue crashing the app' - happy to help if you need additional feedback?

Hope this is useful and to hear back

Regards

jmathai commented 8 years ago

I believe commit 1a1a50e fixes this. Please reopen if it still exists.

ldexterldesign commented 8 years ago

Unfortunately this issue persists:

Traceback (most recent call last):
  File "./elodie.py", line 230, in <module>
    main()
  File "/Library/Python/2.7/site-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/Library/Python/2.7/site-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Library/Python/2.7/site-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Library/Python/2.7/site-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "./elodie.py", line 96, in _import
    trash)
  File "./elodie.py", line 57, in import_file
    media, allowDuplicate=False, move=False)
  File "/Users/ldexterldesign/.Trash/elodie/elodie/filesystem.py", line 182, in process_file
    metadata = media.get_metadata()
  File "/Users/ldexterldesign/.Trash/elodie/elodie/media/text.py", line 71, in get_metadata
    return super(Text, self).get_metadata()
  File "/Users/ldexterldesign/.Trash/elodie/elodie/media/base.py", line 80, in get_metadata
    'date_taken': self.get_date_taken(),
  File "/Users/ldexterldesign/.Trash/elodie/elodie/media/text.py", line 58, in get_date_taken
    if self.metadata_line and 'date_taken' in self.metadata_line:
TypeError: argument of type 'int' is not iterable

Would you care to reopen this issue as I'm unable to do it myself?

Let me know me know if I can be of further help (sorry, I wish I had some Python knowledge)

Regards

jmathai commented 8 years ago

@ldexterldesign I'm not sure how to reproduce this exactly. But I've gone ahead and made the checks for accessing the metadata more strict for checking that it's of type dict across all of the media modules. Try again and see if your problem is fixed. Close the issue if it's fixed.

ldexterldesign commented 8 years ago
Traceback (most recent call last):
  File "./elodie.py", line 230, in <module>
    main()
  File "/Library/Python/2.7/site-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/Library/Python/2.7/site-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Library/Python/2.7/site-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Library/Python/2.7/site-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "./elodie.py", line 96, in _import
    trash)
  File "./elodie.py", line 57, in import_file
    media, allowDuplicate=False, move=False)
  File "/Applications/elodie/elodie/filesystem.py", line 182, in process_file
    metadata = media.get_metadata()
  File "/Applications/elodie/elodie/media/text.py", line 73, in get_metadata
    return super(Text, self).get_metadata()
  File "/Applications/elodie/elodie/media/base.py", line 83, in get_metadata
    'latitude': self.get_coordinate('latitude'),
  File "/Applications/elodie/elodie/media/text.py", line 46, in get_coordinate
    elif type in self.metadata_line:
TypeError: argument of type 'int' is not iterable

Happy to send you the folder of images I'm working with if it helps you reproduce the error your side?

I've tried to single out the file/s in question, but there appears to be quite a few of them 😬

Hope to hear back

Kind thanks

jmathai commented 8 years ago

Please email the zip file to Jaisen at GutHub username dot com.

On Friday, April 15, 2016, Lewis Dexter Litanzios notifications@github.com wrote:

Traceback (most recent call last): File "./elodie.py", line 230, in main() File "/Library/Python/2.7/site-packages/click/core.py", line 716, in call return self.main(_args, _kwargs) File "/Library/Python/2.7/site-packages/click/core.py", line 696, in main rv = self.invoke(ctx) File "/Library/Python/2.7/site-packages/click/core.py", line 1060, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/Library/Python/2.7/site-packages/click/core.py", line 889, in invoke return ctx.invoke(self.callback, _ctx.params) File "/Library/Python/2.7/site-packages/click/core.py", line 534, in invoke return callback(_args, **kwargs) File "./elodie.py", line 96, in _import trash) File "./elodie.py", line 57, in import_file media, allowDuplicate=False, move=False) File "/Applications/elodie/elodie/filesystem.py", line 182, in process_file metadata = media.get_metadata() File "/Applications/elodie/elodie/media/text.py", line 73, in get_metadata return super(Text, self).get_metadata() File "/Applications/elodie/elodie/media/base.py", line 83, in get_metadata 'latitude': self.get_coordinate('latitude'), File "/Applications/elodie/elodie/media/text.py", line 46, in get_coordinate elif type in self.metadata_line: TypeError: argument of type 'int' is not iterable

Happy to send you the folder of images I'm working with if it helps you reproduce it your side?

I've tried to single out the file/s in question, but there appears to be quite a few of them

Hope to hear back

Kind thanks

— You are receiving this because you modified the open/close state. Reply to this email directly or view it on GitHub https://github.com/jmathai/elodie/issues/98#issuecomment-210666742

-- Snet form my mobl phoone

ldexterldesign commented 8 years ago

https://drive.google.com/open?id=0B-oUmf4LFtExMFdvZmctNER2R00

Let me know once you're in receipt of the zip and I'll remove the download

NB Despite attempts to diagnose the issue by removing the erroneous files one by one after each traceback (re: "I've tried to single out the file/s in question, but there appears to be quite a few of them 😬"), I did observe the crash happens every 80 files or so - could this be related to a cache/memory issue instead?

Hopefully you can reproduce the same issue..?

Regards

jmathai commented 8 years ago

@ldexterldesign downloaded. Thanks.

jmathai commented 8 years ago

@ldexterldesign thanks for the zip. The issue was with the file located at 20131207-bea_downie-birthday-london/.dropbox. It was a text file which had a number as it's content. That tripped up the metadata parsing that this library does for text files.

This is a separate issue because a .dropbox file should be skipped. I created #113 for that and will merge it in #114.

ldexterldesign commented 8 years ago

@jmathai hey,

Apologies for delay

Thanks for following this up

Yep, I removed the erroneous Dropbox files and all is well

I'm starting to build quite a collection of these commands now 🙄 ~ https://gist.github.com/ldexterldesign/9c7b8f334657e9f4d50c

Kind thanks

PS Yea, I think any unrecognised/unsupported files should be skipped, and left where they are if using the --trash option