Closed Bug 2061661 Opened 4 months ago Closed 3 months ago

Prefer using oneOf over enums in policy schema

Categories

(Enterprise Products :: Firefox, enhancement, P1)

enhancement

Tracking

(firefox155 fixed)

RESOLVED FIXED
Tracking Status
firefox155 --- fixed

People

(Reporter: bsmth, Assigned: bsmth)

References

Details

Attachments

(1 external file)

The policy schema expresses some allowed values as enums:

"enum": [2, 3]

We have the opportunity to express these as oneOf values with more information, instead:

"oneOf": [
  {
    "const": 2,
    "title": "Block access",
    "description": "Block websites from accessing serial ports. The setting is locked so users cannot change it."
  },
  {
    "const": 3,
    "title": "Allow access",
    "description": "Allow websites to request access to serial ports. Users can still turn this off manually."
  }
]

This will be better for documentation and policy editors, with the downside of producing more verbose errors in PolicySchemaValidator. If these are problematic or not ergonomic to debug in cases where you provide a wrong value, we can follow up with error formatting later.

why is producing more verbose error messages a downside?

I suppose it's not that bad, but for illustration, if you provide a wrong value for HttpsOnlyMode:

Before:

Invalid parameters specified for HttpsOnlyMode: Instance does not match any of
["allowed","disallowed","enabled","force_enabled"]. (at #)

After:

Invalid parameters specified for HttpsOnlyMode: Instance does not match exactly one
subschema (0 matches). (at #); Instance does not match "allowed". (at #); Instance
does not match "disallowed". (at #); Instance does not match "enabled". (at #);
Instance does not match "force_enabled". (at #)

It's a little harder to read with all of the repeated Instance does not match…, especially if there's many possible values. Just noting so we're aware of that.

Should we fix that in cfworker? :)

I love these changes, but the more we diverge from the ESR, the more painful things are going to be to merge to it.

Just something to keep in mind.

Some of these descriptions seem really verbose (and unnecessary).

Do we foresee using them somewhere?

(In reply to Mike Kaply [:mkaply] from comment #4)

Should we fix that in cfworker? :)

There's nothing to fix there as far as I understand, but we can change https://searchfox.org/firefox-main/source/toolkit/components/enterprisepolicies/PolicySchemaValidator.sys.mjs#102 the formatter so we make it a little easier for humans to read. It's a "nice to have", though, in my opinion.

I love these changes, but the more we diverge from the ESR, the more painful things are going to be to merge to it.

Just something to keep in mind.

Gotcha. I think we're nearly done with this topic, so this is as far as the divergence should get.

(In reply to Mike Kaply [:mkaply] from comment #5)

Some of these descriptions seem really verbose (and unnecessary).

Do we foresee using them somewhere?

Yeah, they'll all be surfaced in the console editor. I'll ping Andi who's implementing that for another pair of eyes on it. I'm in the camp of keeping at the current level of detail for UX purposes, but curious what Andi thinks.

Flags: needinfo?(apieper)

Generally, this touches a thorny subject, because we want to translate all user-facing strings in the UI. Difficult with error messages that bubble up from somewhere. Translating the whole error space of the validator sounds like a huge lift.

Editing the policies with a dedicated UI should prevent errors from happening in the first place, and the JSON editor mode should help with auto-completing such enums. So maybe this is not such a big issue.

Other than that, I think this particular Example is a badly phrased message in any case. It basically says the same as the "before" message, only more complicated, less dense and positively robotic..

Flags: needinfo?(apieper)

Other than that, I think this particular Example is a badly phrased message in any case. It basically says the same as the "before" message, only more complicated, less dense and positively robotic..

Which example?

(In reply to Mike Kaply [:mkaply] from comment #8)

Other than that, I think this particular Example is a badly phrased message in any case. It basically says the same as the "before" message, only more complicated, less dense and positively robotic..

Which example?

This one:

Invalid parameters specified for HttpsOnlyMode: Instance does not match exactly one
subschema (0 matches). (at #); Instance does not match "allowed". (at #); Instance
does not match "disallowed". (at #); Instance does not match "enabled". (at #);
Instance does not match "force_enabled". (at #)
Pushed by agoloman@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/9050872b073b https://hg.mozilla.org/integration/autoland/rev/ef9b827ab7cc Revert "Bug 2061661 - Prefer using oneOf over enums in policy schema. r=apieper,mkaply" for causing bc failures @browser_container_definitions_in_sync.js.

Backed out for causing bc failures @browser_container_definitions_in_sync.js.

Flags: needinfo?(brismith)

(In reply to agoloman from comment #12)

Backed out for causing bc failures @browser_container_definitions_in_sync.js.

Latest push contains fixes for the test so it now follows the shape of the schema

Flags: needinfo?(brismith)
Status: NEW → RESOLVED
Closed: 3 months ago
Resolution: --- → FIXED
Flags: qe-verify-
Regressions: 2064379
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: