Closed
Bug 551821
Opened 15 years ago
Closed 15 years ago
Change xpcom.throwFriendlyError so that it returns an Error rather than throwing it
Categories
(Add-on SDK Graveyard :: General, defect)
Add-on SDK Graveyard
General
Tracking
(Not tracked)
RESOLVED
FIXED
0.2
People
(Reporter: adw, Assigned: adw)
Details
Attachments
(1 file, 4 obsolete files)
10.90 KB,
patch
|
Details | Diff | Splinter Review |
See bug 547417 comment 9.
Assignee | ||
Comment 1•15 years ago
|
||
Has a test, which could check that each message for all the supported XPCOM errors is as expected, but that seems kind of unnecessary.
Attachment #432068 -
Flags: review?(avarma)
Comment 2•15 years ago
|
||
Hmm, on the one hand I'd love all our tests to have 100% code coverage and actually exercise all parts of the codebase, but on the other hand, as your last comment implies, writing tests in this context feels like a DRY violation. (DRY stands for "Don't repeat yourself", one of the mantras of Pragmatic Programming.)
I guess DRY violations are actually one of the criticisms of TDD, and I'm not sure how to respond to that. On one hand I have something of an allergic reaction to DRY violations, but on the other hand I feel like it's sometimes necessary to repeat myself to make sure that the code I wrote does what I think it does.
One practical advantage I see of writing tests to ensure that all the supported XPCOM errors are as expected is that we have the freedom to refactor this code if necessary, and be certain that it still works as expected.
I'm pinging mhanson to chime in here to see what he has to say.
Assignee | ||
Comment 3•15 years ago
|
||
That's reasonable, and it's not a big deal to update the patch to check, so here's a new patch. :)
Attachment #432068 -
Attachment is obsolete: true
Attachment #432189 -
Flags: review?(avarma)
Attachment #432068 -
Flags: review?(avarma)
Comment 4•15 years ago
|
||
Whoa, thanks.
The only other test I can think of is making sure that the 'traceback' module can generate proper stack tracebacks from the kind of exception that friendlyError() returns. This could be something like:
exports.testFriendlyErrorsHaveTracebacks = function(test) {
var exc = xpcom.friendlyError(Cr.NS_ERROR_FILE_IS_DIRECTORY);
var tb = require("traceback").fromException(exc);
test.assert(tb.length > 1);
}
That's not really a unit test per say, but it'd be useful to have... It might be more appropriate to put it in the traceback module, I'm not sure.
Aside from that, the only thing I'd suggest is keeping documentation for the various keys that the 'opts' argument supports, which right now I think is just 'filename'.
(We should actually document the xpcom module itself in the SDK docs, I think, but that sounds like a matter for another bug!)
Assignee | ||
Comment 5•15 years ago
|
||
> var tb = require("traceback").fromException(exc);
> test.assert(tb.length > 1);
This patch does exactly that, and tests pass, so I guess it works? I added these checks to the xpcom test, since it's testing a property of the objects returned by friendlyError in particular.
> Aside from that, the only thing I'd suggest is keeping documentation for the
> various keys that the 'opts' argument supports, which right now I think is just
> 'filename'.
I used the @prop syntax suggested by Aza, but I'm not sure everyone ever agreed on it.
> (We should actually document the xpcom module itself in the SDK docs, I think,
> but that sounds like a matter for another bug!)
I'd file this bug, but I don't know how doc tasks are being tracked.
Attachment #432189 -
Attachment is obsolete: true
Attachment #432236 -
Flags: review?(avarma)
Attachment #432189 -
Flags: review?(avarma)
Assignee | ||
Comment 6•15 years ago
|
||
Sorry, small change in the test.
Attachment #432236 -
Attachment is obsolete: true
Attachment #432237 -
Flags: review?(avarma)
Attachment #432236 -
Flags: review?(avarma)
Comment 7•15 years ago
|
||
Nice. I'm gonna r+ this, but the following suggestions are nits that you don't need to follow if you don't want:
* It's preferable to have a third string param to all the asserts that explains "in plain english" (or somewhat close to it) what's being asserted.
* I don't think the docs for opts.filename really need to list out all the NS_ERROR_* constants it matches; it could just say "the name of a file being accessed when the exception was thrown, if any"--and then we could just use our own discretion to include its information whenever it might be useful.
* Is there a particular reason Cr.NS_ERROR_FILE_IS_DIRECTORY doesn't use opts.filename if it's available? Seems like it could be useful there...
Lastly, we're not currently tracking documentation tasks any differently from coding tasks, so feel free to just file a bug in the Jetpack SDK component! Thanks!
Updated•15 years ago
|
Attachment #432237 -
Flags: review?(avarma) → review+
Assignee | ||
Comment 8•15 years ago
|
||
Thanks Atul. This fixes those three nits. I filed bug 552109 for the docs.
Attachment #432237 -
Attachment is obsolete: true
Assignee | ||
Comment 9•15 years ago
|
||
Status: ASSIGNED → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
Comment 10•15 years ago
|
||
Awesome, thanks Drew!
Comment 11•15 years ago
|
||
The Add-on SDK is no longer a Mozilla Labs experiment and has become a big enough project to warrant its own Bugzilla product, so the "Add-on SDK" product has been created for it, and I am moving its bugs to that product.
To filter bugmail related to this change, filter on the word "looptid".
Component: Jetpack SDK → General
Product: Mozilla Labs → Add-on SDK
QA Contact: jetpack-sdk → general
Version: Trunk → unspecified
You need to log in
before you can comment on or make changes to this bug.
Description
•