Open Bug 1580610 Opened 5 years ago Updated 2 years ago

Preferences.jsm .get() for user-set but no default pref throws NS_ERROR_UNEXPECTED

Categories

(Toolkit :: Preferences, defect, P5)

defect

Tracking

()

People

(Reporter: Mardak, Unassigned)

References

Details

({Preferences} = ChromeUtils.import("resource://gre/modules/Preferences.jsm"));
(new Preferences()).set("foo", 5);
(new Preferences({ defaultBranch: true })).get("foo");

[Exception... "Component returned failure code: 0x8000ffff (NS_ERROR_UNEXPECTED) [nsIPrefBranch.getIntPref]"  nsresult: "0x8000ffff (NS_ERROR_UNEXPECTED)"  location: "JS frame :: resource://gre/modules/Preferences.jsm :: Preferences._get :: line 67"  data: no]

Looks like getPrefType returns a type based on the user set pref, so then it tries to get the value of that type, but there's no actual value on the default pref branch.

I'd strongly advise against using Preferences.jsm, and in favour of using default values, Services.prefs, and lazy pref getters.

I don't think we'll prioritize fixing this any time soon.

Priority: -- → P5

Looks like bug 1385952 might be getting rid of activitystream's usage of Preferences.jsm anyway although it might just end up copying over various methods from Preferences.jsm

See Also: → 1385952
Severity: normal → S3
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.