Closed
Bug 618721
Opened 14 years ago
Closed 13 years ago
If page-mod's 'include' option's value is invalid, incorrect error is shown.
Categories
(Add-on SDK Graveyard :: General, defect)
Add-on SDK Graveyard
General
Tracking
(Not tracked)
RESOLVED
FIXED
People
(Reporter: KWierso, Assigned: KWierso)
References
Details
Attachments
(1 file, 1 obsolete file)
1.09 KB,
patch
|
myk
:
review+
|
Details | Diff | Splinter Review |
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0b8pre) Gecko/20101211 Firefox/4.0b8pre Build Identifier: I was trying to play around with SDK 1.0b1, and wanted to use the page-mod module. I wanted the page mod to run on all pages in the roosterteeth.com domain, so I wrote my code like this: var pageMod = require("page-mod"); pageMod.PageMod({ include: ["roosterteeth.com"], contentScriptWhen: 'ready', contentScript: 'document.body.innerHTML = ' + ' "<h1>Page matches ruleset</h1>";' }); Now when I tried to do cfx run, I get the following error: Error: The PageMod must have a string or array `include` option. This threw me off, because there clearly IS an include option in there. I tried removing the array brackets from it, and it still gave me that error. Now, when I replaced "roosterteeth.com" with "*", it ran just fine. Looking through the documentation, I should have used "*.roosterteeth.com", to correctly use match-pattern's... pattern. It'd be nice if the SDK told me that I failed to use match-pattern correctly, instead of being told that 'include' isn't there. Reproducible: Always
Assignee | ||
Updated•14 years ago
|
Summary: If page-mod's include option's value is invalid, incorrect error is shown. → If page-mod's 'include' option's value is invalid, incorrect error is shown.
Assignee | ||
Comment 1•13 years ago
|
||
Oh, I see what's going on. match-pattern is throwing an error on line 61, but page-mod's try-catch block on lines 112-120 are eating it and replacing it with the "must have a string or array" error.
Assignee | ||
Comment 2•13 years ago
|
||
This lets match-pattern's more accurate error bubble up. What was the try/catch's original error supposed to prevent? Other than string and array, what could it be (numeric, object)? It'd probably be better to explicitly check those kinds of things than just a catch-all like it was.
Assignee | ||
Comment 3•13 years ago
|
||
This lets match-pattern's errors bubble up AND it validates 'include' against numbers and non-Array objects.
Attachment #512564 -
Attachment is obsolete: true
Attachment #512582 -
Flags: review?(dietrich)
Comment 4•13 years ago
|
||
Comment on attachment 512582 [details] [diff] [review] v2 >diff --git a/packages/addon-kit/lib/page-mod.js b/packages/addon-kit/lib/page-mod.js >+ // Validate 'include' >+ if(typeof(include) == "object" && !Array.isArray(include)) >+ throw new Error(ERR_INCLUDE) >+ if(typeof(include) == "number") >+ throw new Error(ERR_INCLUDE) This should throw ERR_INCLUDE if include is undefined as well, since ERR_INCLUDE is more descriptive than the "pattern is undefined" exception that match-pattern will throw in that case, and to fix the test-page-mod.testPageModErrorHandling test, which expects ERR_INCLUDE. Also, style nits: add a space between "if" and "(" and semi-colons at the ends of statements. r=myk with those changes!
Attachment #512582 -
Flags: review?(dietrich) → review+
Comment 5•13 years ago
|
||
Pushed with the changes requested in the review comments to get it in before today's 1.0b3 freeze: https://github.com/mozilla/addon-sdk/compare/36c708f...30f4b49 I also removed the try/catch block, which is unnecessary now that we propagate the match-pattern exception unaltered. Thanks for the fix!
Assignee: nobody → kwierso
Status: UNCONFIRMED → RESOLVED
Closed: 13 years ago
OS: Windows 7 → All
Hardware: x86 → All
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•