Closed Bug 1127277 Opened 10 years ago Closed 9 years ago

Calling Bookmarks.insert() without a type throws an unhelpful error

Categories

(Toolkit :: Places, defect)

defect
Not set
normal
Points:
2

Tracking

()

RESOLVED FIXED
mozilla39
Iteration:
39.2 - 23 Mar
Tracking Status
firefox39 --- fixed

People

(Reporter: ttaubert, Assigned: ttaubert)

References

(Blocks 1 open bug)

Details

Attachments

(1 file, 1 obsolete file)

Sometimes when converting tests to the new Bookmarks API I would forget specifying a type property when calling Bookmarks.insert() to create a bookmark. When passing a URI as one does when inserting a bookmark it will fail with:

Invalid value for property 'url': http://example.com/

The |validIf| for |url| fails before we even start checking for required properties. Knowing that |type| is required would however be much more helpful than telling me the value for |url| is invalid :)
yeah, actually we wanted to make type optional if url is provided, since it's clear it's a TYPE_BOOKMARK
That sounds like a good idea too!
Points: --- → 2
Flags: qe-verify-
Flags: firefox-backlog+
Blocks: 1141547
Assignee: nobody → ttaubert
Status: NEW → ASSIGNED
Attachment #8575983 - Flags: review?(mak77)
Iteration: --- → 39.2 - 23 Mar
Comment on attachment 8575983 [details] [diff] [review]
0001-Bug-1127277-Default-to-TYPE_BOOKMARK-when-no-type-is.patch

Review of attachment 8575983 [details] [diff] [review]:
-----------------------------------------------------------------

::: toolkit/components/places/Bookmarks.jsm
@@ +148,2 @@
>      let insertInfo = validateBookmarkObject(info,
>        { type: { required: true }

wouldn't be the same if you'd just replace required: true here with defaultValue: this.TYPE_BOOKMARK ?

::: toolkit/components/places/tests/bookmarks/test_bookmarks_insert.js
@@ +251,5 @@
> +add_task(function* create_bookmark_without_type() {
> +  let bm = yield PlacesUtils.bookmarks.insert({ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
> +                                                url: "http://example.com/",
> +                                                title: "a bookmark" });
> +  checkBookmarkObject(bm);

additionally check it's a TYPE_BOOKMARK and the url?
Attachment #8575983 - Flags: review?(mak77) → feedback+
Attachment #8575983 - Attachment is obsolete: true
Attachment #8576117 - Flags: review?(mak77)
Comment on attachment 8576117 [details] [diff] [review]
0001-Bug-1127277-Default-to-TYPE_BOOKMARK-when-no-type-is.patch, v2

Review of attachment 8576117 [details] [diff] [review]:
-----------------------------------------------------------------

::: toolkit/components/places/Bookmarks.jsm
@@ +139,5 @@
>      // Ensure to use the same date for dateAdded and lastModified, even if
>      // dateAdded may be imposed by the caller.
>      let time = (info && info.dateAdded) || new Date();
>      let insertInfo = validateBookmarkObject(info,
> +      { type: { required: true, defaultValue: this.TYPE_BOOKMARK }

defaultValue makes required pointless.
Attachment #8576117 - Flags: review?(mak77) → review+
https://hg.mozilla.org/mozilla-central/rev/d31ed2b38332
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Target Milestone: --- → mozilla39
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: