Closed
Bug 1160109
Opened 10 years ago
Closed 10 years ago
Handling OSFile errors is unnecessarily complex due to different error types across platforms
Categories
(Toolkit Graveyard :: OS.File, defect)
Toolkit Graveyard
OS.File
Tracking
(Not tracked)
RESOLVED
WORKSFORME
People
(Reporter: standard8, Unassigned)
Details
OSFile's error handling causes really complex code. For some code I'm writing in Loop, I need to attempt to read a file, and then only log an error if the error is not "file not found".
Currently OSFile gives a custom error, and its different across platforms, so I have to do:
if ((OS.Constants.libc && error.unixErrno != OS.Constants.libc.ENOENT) ||
(OS.Constants.Win && error.winLastError != OS.Constants.Win.ERROR_FILE_NOT_FOUND)) {
...etc
Really this should be something like:
if (error.errno == Cr.NS_ERROR_FILE_NOT_FOUND) {
which would be much simpler and less prone to errors.
Comment 1•10 years ago
|
||
Actually, XPCOM errors are very bad at matching file errors. In many cases, there is no XPCOM error for a given file error, and in some cases there are several. However, OS.File defines a number of `becauseXXX` helpers to help with this purpose:
Here, your code should look like
`if (error.becauseNoSuchFile) {
}`
Which I believe is even better than what you request. If you find missing `becauseXXX` getters, don't hesitate to file bugs.
Comment 2•10 years ago
|
||
In the absence of response, I'm WONTFIXing this. Please reopen if you feel I have missed something.
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → WORKSFORME
Updated•2 years ago
|
Product: Toolkit → Toolkit Graveyard
You need to log in
before you can comment on or make changes to this bug.
Description
•