Repository navigation
Conversation
Proposes a check function family that returns a structured result: a reason code, a details object and a policy for undeclared limits. The proposal answers the questions in openscd#109: - expected refusals are returned, not thrown - one reason vocabulary across all element families - no user text or translation inside the library The proposal rests on a study of 716 real SCL files. Closes openscd#109
|
We might never merge this but we could at least use it to comment/discuss |
Applies the outcome of the review discussion and restructures the document: - One result object, discriminated by key, with a finished English sentence in reasonText. No lang parameter. - all: true on check* returns every independent reason, with collected reasons and no second function. - 2.1.0 with new check* names; the old names stay and are deprecated. - Three pull requests, so the counting fix has its own review. - limitPolicy is a shared option of the check function and the create function. D5 gives the target default and the release that applies it. - maxAttributes keeps its type; only its undeclared branch changes. - checkRemove* takes no force parameter. - Report limits count blocks, not instances, in 2.1. - Fixed order of reasons, with a test. - Appendix D.1 gives the rule for choosing a reason code. - Appendix F gives a sketch, a checklist and one full implementation. The evidence section now states what we did, why, what we found and what each finding changed in the design. Closes openscd#109
1065e4e to
b8a35f0
Compare
ca-d
left a comment
There was a problem hiding this comment.
Hey Daniel,
Thank you very much for this extremely thorough work and your inexhaustible patience in waiting for any feedback to materialize.
I support decisions 1, 2, 4, and 15.
I am still weary of the long-term maintenance cost of including and maintaining 25 tested English sentences (plus plural handling). I don't know why having this hard-wired into the check API for all time is so desperately important. I think if people just have a way to get a ready-made description for a given SclReason, most users won't care how inextricably it's interwoven into the fabric of this API. But I predict the maintainers will start caring quite a bit, sooner or later.
I'd love to return all relevant SclReasons in one single ValidityState-like object where we give details under these beautiful, well-known, unique keyes. Do you see reasons against doing so or in favour of the current "main reason plus array" approach? I don't yet see the need for this fixed ordering of reasons, but I see good reasons speaking against it from a maintenance perspective.
Apart from these points, there appears to be inconsistency between C.2 and C.3, and between F.2 and F.7/F.8, respectively.
Thank you again for this momentous work, I hope we can move forward based on this proposal.
| | Situation | Channel | | ||
| |---|---| | ||
| | Expected refusal, for example a maximum | Returned `{ allowed: false, reason, reasons? }` | | ||
| | Incorrect call, for example a value that is not an element | Thrown `SclError` with the same variants | |
There was a problem hiding this comment.
What's the reason for defining that SclError shall contain exactly the same reason description data? Is every single reason for not being able to do something also a possible reason for throwing an error? Is this also true the other way around? Neither seems immediately obvious to me.
| The order is fixed. The first reason is the one that a row shows, so the order is part of the contract. | ||
|
|
||
| The rule for the order: **a reason that the user cannot correct in this operation comes before a reason that the user can correct here.** A message that asks the user to rename an element is wrong when the device cannot accept the element at all. |
There was a problem hiding this comment.
Why do we need reasons to be ordered in this fashion?
I would generally expect that a check function that only returns a single error would return the first one it algorithmically happens to find (fail as quickly as possible), and that a check function which returns multiple reasons does something broadly like ValidityState (only with extra data rather than just booleans) where I get an unordered object that has one key per reason it won't work. What speaks against this way?
| 3. A supervision rule uses these categories. It does not need a new category. | ||
| 4. One vocabulary serves the `check*` functions and the document check. | ||
|
|
||
| Appendix D gives all 25 codes, their fields, their source and the rule for choosing one. |
There was a problem hiding this comment.
I very much like this idea of having a closed set of unique keys (open to growth by extension later, promising never to break by removing or reinterpreting existing keys); I'd also like to see these explicitly exported as some kind of enumeration or TS typed const array.
| | # | Question | Preferred | Cost of the other option | | ||
| |---|---|---|---| | ||
| | D1 | Add a check function, or change the create function? | Add a check function | Breaks every call site | | ||
| | D2 | One reason vocabulary, or one for each family? | One vocabulary for all families | One `switch` for each family in each host | |
There was a problem hiding this comment.
I like one shared reason vocabulary for all checks, and I'd like to get our usage of this vocabulary even closer to the relevant prior art, viz. what W3C are doing with ValidityState:
- Let's have an exported
SclReasonkey union and document the guarantee that we will only ever add further keys or add more reason data to existing keys, and that we will never re-interpret keys, remove keys, or remove provided reason data from an existing key (causing downstream breakage). - Let's return reasons not as an array of objects, but instead as a strongly typed single object keyed by reason key with the reason details given in the corresponding value (where ValidityState uses
boolean). - Let's thereby get rid of the brittle idea of fixing reason ordering in the API.
- Even if only a single reason is returned (e.g. because
!allis specified), I can just return an object with only one key and its detail value, I don't see a reason for separatingreasonandreasonsin this way.
| |---|---|---|---| | ||
| | D1 | Add a check function, or change the create function? | Add a check function | Breaks every call site | | ||
| | D2 | One reason vocabulary, or one for each family? | One vocabulary for all families | One `switch` for each family in each host | | ||
| | D3 | Does the library return user-facing text with a refusal? | Yes, one English sentence | The host writes every message | |
There was a problem hiding this comment.
I completely understand that casual users of this code may simply want some end-user facing string to display, which they do not care to control. Let's provide them one!
Also, I am still horrified by the prospect of having to maintain and test the content of these English-language end-user facing strings — which are explicitly not part of the API yet contradictorily still required to be tested for correctness in this proposal — inside the same codebase. Please let's have a helper function elsewhere in a utils repository that translates SclReason to string. With that separation of concerns cleanly drawn at the code maintenance level, I predict that even allowing the addition of arbitrary translations would be feasible and welcome.
If for some masochistic reason the maintainers of this library desperately want to have these strings in the same codebase, I would still very strongly suggest moving the description to a separate describeReason function in a separate code file with a separate entry point so it can at least be cleanly tree-shook, have its own separate tests, and be more clearly not part of the API (the boundary of which is currently conceptually muddled in this proposal).
|
|
||
| | # | Question | Preferred | Cost of the other option | | ||
| |---|---|---|---| | ||
| | D1 | Add a check function, or change the create function? | Add a check function | Breaks every call site | |
There was a problem hiding this comment.
For convenience we could additionally collect all check functions for the appropriate edit functions in a global map and provide a generic check(editFunctionToCheck, options, editFunctionParameters...) function.
| |---|---|---| | ||
| | Counting rule | blocks, in both functions | blocks | | ||
| | `limitPolicy` | accepted by both functions. Default `refuse`. | accepted by both functions. Default `permit`. | | ||
| | Report options | `check*` reads them. `create*` ignores them. | both read them | |
There was a problem hiding this comment.
This seems to break the test proposed in the next section. If this is truly necessary and on purpose for SCL standards reasons I do not yet understand, we should explicitly document it. Specifically, that test seems to require both check and create to follow the same rule here. Am I misunderstanding?
| current, | ||
| max, | ||
| affected: [], | ||
| reasonText: `The maximum number of ${tag} instances (${current} of ${max}) has been reached.`, |
There was a problem hiding this comment.
This appears to contradict the expected result in the F.7 test and the F.8 example.
| expect(check.reason.key).to.equal("limit-reached"); | ||
| expect(check.reason).to.include({ current: 12, max: 12 }); | ||
| expect(check.reason.reasonText).to.equal( | ||
| "The maximum number of DataSets (12 of 12) has been reached.", |
There was a problem hiding this comment.
Missing the word "instances", pluralizing DataSets instead.
Et ceterum censeo: Pluralization and these tricky problems stemming from multiple but potentially contradictory apparent sources of truth in the same object are just two of the reasons why I still believe English language strings are best segregated.
|
|
||
| addButton.disabled = !check.allowed; | ||
| addButton.title = check.allowed ? "" : check.reason.reasonText; | ||
| // "The maximum number of DataSets (12 of 12) has been reached." |
There was a problem hiding this comment.
(same in this comment as in the test above in F.7)
What this pull request does
Adds one document:
docs/proposals/0001-public-check-api.md. No code changes.The document proposes a public check API for scl-lib: a family of
check*functions that answer "can this operation be done, and if not, why". It also proposes one error model, one reason vocabulary and one policy for limits that a file does not declare.Why
Issue #109 asks how the library should handle a function that fails. Today a caller gets
nullor[]and cannot tell why. Four element families have acanAdd*check that is not exported, and the two public checks return a bare boolean.Evidence
The design rests on a study of 716 real SCL files (120 sampled plus the four largest). Section 2 gives the results and Appendix A gives the method and the full table.
Serviceselement, and 58 of 120 files use a service that they do not declare. A strict default blocks edits in those files.ConfReportControl@maxcounts control blocks, notRptEnabled@maxinstances. The current rule refuses 72 scopes in 24 of 120 files; the block rule refuses 6 in 2.lnType,datSet,iedName). The library must report them and must not use them to refuse an unrelated edit.Shape after the review
key, with a finished English sentence inreasonText(D3). Nolangparameter.all: trueoncheck*returns every independent reason. No second function (Appendix B).check*is added; the old names stay and are deprecated. New names make the addition additive.check*,can*andcreate*(D15). It only removes refusals.limitPolicydefaults torefusein 2.x and flips topermitin 3.0 (D5). A file that declares no limit becomes editable in 3.0, not before.checkAddDataSet(Appendix F), with the sketch first and a checklist of the rules an author must keep.How to review
Section 5 has 15 decisions. Each gives the options and our preferred answer. Reply with the decision number and the letter, for example
D5: B, or comment on any line of the diff.Three decisions still need an explicit yes from the reviewers who raised them:
Scope of this pull request
npm testis unaffected: the change contains no TypeScript and no test.Changes
docs/proposals/0001-public-check-api.md(new, 1127 lines)