Closed Bug 465863 Opened 16 years ago Closed 16 years ago

[silme] Improve exception handling in io.file.py

Categories

(Mozilla Localizations :: Infrastructure, defect)

defect
Not set
major

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: adriank, Assigned: adriank)

References

Details

Attachments

(1 file)

Attached patch patch v1Splinter Review
We have some problems with the exception handling in silme.io.file. The submitted patch fixes:

-don't fall silently on every possible exception
-fix raising UnicodeDecodeError (it's causing a TypeError at the moment)
-add TODOs for exceptions that should be logged in the future (after the silme.core.logging lands)
Comment on attachment 349096 [details] [diff] [review]
patch v1

>diff --git a/lib/silme/io/file.py b/lib/silme/io/file.py
>--- a/lib/silme/io/file.py
>+++ b/lib/silme/io/file.py

>   @classmethod
>   def getSourceWithEncoding(cls, path, encoding):
>     try:
>       f = codecs.open(path, 'rU', encoding=encoding)
>       text = f.read()
>     except UnicodeDecodeError, e:
>-      raise UnicodeDecodeError(path + ': ' + str(e))
>+      raise UnicodeDecodeError, e
>     except IOError, e:
>       raise IOError(path + ': ' + str(e))

why do you remove path here?

except of this it looks good.
Gandalf: because you cannot raise a UnicodeDecodeError with only one argument. If you don't do that with exactly 5 arguments, it'll raise a TypeError.
Attachment #349096 - Flags: review?(gandalf)
Attachment #349096 - Flags: review?(gandalf) → review+
commited
Status: ASSIGNED → RESOLVED
Closed: 16 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: