Opened 15 years ago

Closed 15 years ago

Last modified 11 years ago

#1040 closed defect (fixed)

Traceback when copying file of unknown MIME type to USB stick

Reported by: sascha_silbe Owned by: tomeu
Priority: Unspecified by Maintainer Milestone:
Component: Sugar Version: Git as of bugdate
Severity: Unspecified Keywords: r+
Cc: Distribution/OS: Unspecified
Bug Status: New

Description

When trying to copy a Calculate instance I get the following traceback:

Traceback (most recent call last):

File "/home/sascha.silbe/sugar-jhbuild/install/lib/python2.5/site-packages/jarabe/journal/volumestoolbar.py", line 141, in _drag_data_received_cb

model.copy(metadata, self.mount_point)

File "/home/sascha.silbe/sugar-jhbuild/install/lib/python2.5/site-packages/jarabe/journal/model.py", line 459, in copy

return write(metadata, file_path)

File "/home/sascha.silbe/sugar-jhbuild/install/lib/python2.5/site-packages/jarabe/journal/model.py", line 487, in write

file_name = _get_file_name(metadatatitle?, metadatamime_type?)

File "/home/sascha.silbe/sugar-jhbuild/install/lib/python2.5/site-packages/jarabe/journal/model.py", line 499, in _get_file_name

extension = '.' + mime.get_primary_extension(mime_type)

TypeError: cannot concatenate 'str' and 'NoneType' objects

This is because sugar.mime.get_primary_extension() returns None if no extension for the given MIME type is known.
The attached patch handles this case by substituting the empty string instead.

Attachments (1)

sugar-journal-unknown-mime-extension.patch (571 bytes) - added by sascha_silbe 15 years ago.
use empty extension if sugar.mime.get_primary_extension() returns None

Download all attachments as: .zip

Change History (6)

comment:1 Changed 15 years ago by tomeu

  • Keywords r- added; r? removed

Wonder if we should omit the dot entirely if we don't know an appropriate exception?

Changed 15 years ago by sascha_silbe

use empty extension if sugar.mime.get_primary_extension() returns None

comment:2 Changed 15 years ago by sascha_silbe

  • Keywords r? added; r- removed

Oops, good catch. New version attached.

comment:3 Changed 15 years ago by tomeu

  • Keywords r+ added; r? removed

Please try to follow the PEP 8 recommendations and specially the style of the already existing code. I have modified your code to comply with that, is more verbose but safer and more readable.

http://git.sugarlabs.org/projects/sugar/repos/mainline/commits/81eaa9b6f3

Specifically:

    - Comparisons to singletons like None should always be done with
      'is' or 'is not', never the equality operators.

      Also, beware of writing "if x" when you really mean "if x is not None"
      -- e.g. when testing whether a variable or argument that defaults to
      None was set to some other value.  The other value might have a type
      (such as a container) that could be false in a boolean context!
    Avoid extraneous whitespace in the following situations:

    - Immediately inside parentheses, brackets or braces.

      Yes: spam(ham[1], {eggs: 2})
      No:  spam( ham[ 1 ], { eggs: 2 } )

    - Immediately before a comma, semicolon, or colon:

      Yes: if x == 4: print x, y; x, y = y, x
      No:  if x == 4 : print x , y ; x , y = y , x

Thanks a lot for the patch!

comment:4 Changed 15 years ago by tomeu

  • Resolution set to fixed
  • Status changed from new to closed

comment:5 Changed 11 years ago by dnarvaez

  • Milestone 0.86 deleted

Milestone 0.86 deleted

Note: See TracTickets for help on using tickets.