Repository navigation
feat(cloud-registry): show field errors in form - #595
Conversation
When Cloud Registry rejects a registration with field errors in its problem details (RFC 9457 `errors` with `pointer` or `parameter`), the service create form now shows each message at its field, using `parseProblemDetails()` and `mapFieldErrors()` of `@elixir-cloud/design/utils` and the controls' `error` property. - Errors of a listed type's parts show at the type list; with a new type, at the group, artifact and version fields. - Errors of the admin fields open "Advanced Configuration". - A field's error is cleared when it changes; all on reset and submit. - Only fields that the request sent are mapped. - `ecc-service-create-failed` gets `fieldErrors` and `generalError` (the rest for the app to show); `error` is unchanged. Docs: field errors on the component page, and the provider's Errors. Closes #536 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reviewer's GuideAPIExtend the public
ImplementationParse provider problem details, map errors only to fields the request can send, and track which field errors remain applicable as the form changes or a create completes.
UIBind the mapped errors to the corresponding controls so users see each registry message under its field.
ConfigurationRecord the minor package release and summarize the new field-error behavior in the changeset.
DocumentationDocument how service-create field errors are mapped and shown, and describe the new event fields and application error-handling pattern.
TestsAdd coverage for provider error mapping, field visibility and clearing, in-flight edits and resets, and the event detail.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Documentation build overview
53 files changed ·
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #595 +/- ##
==========================================
+ Coverage 77.46% 78.05% +0.59%
==========================================
Files 76 76
Lines 19477 19639 +162
Branches 1268 1317 +49
==========================================
+ Hits 15087 15330 +243
+ Misses 4368 4289 -79
+ Partials 22 20 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Linked issuesChecked at commit 26100ec #536 feat(cloud-registry): show the registry's field errors · 4 of 4 met
|
There was a problem hiding this comment.
Hey - I've found 6 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="packages/ecc-client-elixir-cloud-registry/src/components/service-create/service-create.ts" line_range="399-402" />
<code_context>
+ type: "/type",
+ version: "/version",
+ description: "/description",
+ contactUrl: "/contactUrl",
+ documentationUrl: "/documentationUrl",
+ environment: "/environment",
+ };
+ if (this.newType) {
+ locations["type.group"] = "/type/group";
</code_context>
<issue_to_address>
**Omitted fields show the wrong error**
When an optional field is blank and omitted from the request, but the registry returns an error for it, `fieldLocations()` still maps the omitted field, so `handleSubmit()` places its error in `fieldErrors` instead of `generalError`; the user sees an error beside a field they did not send.
Only map errors to fields that were included in the request, and leave errors for omitted fields in `generalError`.
Also at `packages/ecc-client-elixir-cloud-registry/src/components/service-create/service-create.ts:408-411`.
</issue_to_address>
### Comment 2
<location path="packages/ecc-client-elixir-cloud-registry/src/components/service-create/service-create.ts" line_range="687" />
<code_context>
private async handleSubmit(): Promise<void> {
const provider = this.currentProvider();
if (!provider || !provider.createService) {
+ const error = "Service creation is not supported by the current provider";
this.dispatchEvent(
new CustomEvent("ecc-service-create-failed", {
</code_context>
<issue_to_address>
**Previous field errors remain visible**
When a create has populated `fieldErrors` and the next submit has no provider or a provider without `createService`, `handleSubmit()` dispatches the unsupported-provider failure and returns before clearing `fieldErrors`, so errors from the previous create remain visible despite the new event reporting an empty field-error map.
Clear `fieldErrors` before the unsupported-provider check in `handleSubmit()`.
Also at `packages/ecc-client-elixir-cloud-registry/src/components/service-create/service-create.ts:690`, `packages/ecc-client-elixir-cloud-registry/src/components/service-create/service-create.ts:699`.
</issue_to_address>
### Comment 3
<location path="packages/ecc-client-elixir-cloud-registry/src/components/service-create/service-create.ts" line_range="787" />
<code_context>
+ locations,
+ });
+ // the registry's field errors show at the fields
+ this.fieldErrors = detail.fieldErrors;
this.dispatchEvent(
new CustomEvent("ecc-service-create-failed", {
</code_context>
<issue_to_address>
**Late errors appear on the changed form**
When the user edits or resets the form, or changes from a new type to a listed type, while a create request is pending and that request returns field errors, the catch handler assigns errors from the submitted request to the current form; this restores errors for old values or stores new-type errors for controls that are no longer rendered, leaving the user with stale or invisible errors.
Apply a failed request's field errors only if the form state and type mode still match those submitted with the request.
Also at `packages/ecc-client-elixir-cloud-registry/src/components/service-create/service-create.ts:403-407`.
</issue_to_address>
### Comment 4
<location path="packages/ecc-client-elixir-cloud-registry/src/components/service-create/service-create.ts" line_range="1237" />
<code_context>
</ecc-utils-design-label>
<ecc-utils-design-input
id="custom-service-id"
+ .error=${this.fieldError("serviceId")}
.value=${this.formData.customServiceId}
@ecc-input-changed=${(e: CustomEvent) => {
</code_context>
<issue_to_address>
**Admin field errors disappear**
When admin-only field errors were mapped after a failed create, then the component's `admin` property changes to false, `renderAdvancedFields()` hides these controls when `admin` becomes false, but their mapped errors remain in `fieldErrors`; because `generalError` was `undefined` when the errors matched, neither the form nor an app following the documented `generalError` guidance shows them.
When `admin` becomes false, clear those errors or move them into a general error that remains available to the app.
Also at `packages/ecc-client-elixir-cloud-registry/src/components/service-create/service-create.ts:1262`, `packages/ecc-client-elixir-cloud-registry/src/components/service-create/service-create.ts:1280`.
</issue_to_address>
### Comment 5
<location path="packages/ecc-client-elixir-cloud-registry/src/components/service-create/service-create.ts" line_range="1016" />
<code_context>
return html`
<ecc-utils-design-input
id="environment"
+ .error=${this.fieldError("environment")}
.value=${this.formData.environment}
@ecc-input-changed=${(e: CustomEvent) =>
</code_context>
<issue_to_address>
**Cleared environment retains its error**
When an options update causes `willUpdate()` to clear the environment value after a create set an environment field error, `willUpdate()` clears `formData.environment` without clearing its registry error, so the error remains visible beside the cleared field.
Clear the environment field error whenever `willUpdate()` clears the environment value.
Also at `packages/ecc-client-elixir-cloud-registry/src/components/service-create/service-create.ts:1028`.
</issue_to_address>
### Comment 6
<location path="packages/ecc-client-elixir-cloud-registry/src/components/service-create/tests/service-create-field-errors.test.ts" line_range="354-357" />
<code_context>
+ headers: { "Content-Type": "application/json" },
+ });
+ const created = oneEvent(el, "ecc-service-created");
+ internals(el).handleSubmit();
+ await created;
+ await el.updateComplete;
+ expect(control(el, "service-name").error).to.equal("");
+
+ answer = () => invalid([{ detail: "Too long.", pointer: "#/name" }]);
</code_context>
<issue_to_address>
**Submit clearing is not isolated**
When a previous submission set a field error and the next submission succeeds, when the new submit succeeds, the `clears the field errors on a new submit and on reset` test checks the empty error only after the success event and update. The successful-create reset clears it too, so the test passes even if starting a new submit leaves the old field error visible.
Use a second response without field errors and assert the old field error is cleared after that submission, independently of the successful-create reset.
</issue_to_address>Sourcery assessment
Approval pending. 6 findings to address first.
Blocking findings: packages/ecc-client-elixir-cloud-registry/src/components/service-create/service-create.ts:402, packages/ecc-client-elixir-cloud-registry/src/components/service-create/service-create.ts:687, packages/ecc-client-elixir-cloud-registry/src/components/service-create/service-create.ts:787, packages/ecc-client-elixir-cloud-registry/src/components/service-create/service-create.ts:1237, packages/ecc-client-elixir-cloud-registry/src/components/service-create/service-create.ts:1016, and 1 more
Clear the field errors when the provider cannot create, when admin is turned off (admin-only fields) and when the environment is dropped. Do not show errors of fields that changed while the create ran, nor any after a reset in that time; the event still reports them all. Isolate the test of clearing on a new submit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace the reset counter and the set of changed fields with one token per create, so that a create only applies its field errors while it is still the running one. Undo the reformat of the component page, keep only its new text, and align the event docs with the hidden errors. Test that choosing another type clears its error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Move "Field errors" out of Events into its own section, cut it to what apps need, shorten the changeset, and test that the auto-opened Advanced Configuration trigger reports aria-expanded.
Summary
The Cloud Registry service create form shows the registry's field errors at the fields they belong to, using the field-error support of
@elixir-cloud/design(#535, #576). Cloud Registry 1.0.0rc2 lists every invalid field of a rejected registration inerrorsof its problem details (elixir-cloud-aai/cloud-registry#317, elixir-cloud-aai/cloud-registry#378). This unblocks elixir-cloud-aai/cloud-registry-ui#132.ecc-client-elixir-cloud-registry-service-createreads the problem details from the provider's error (problemofCloudRegistryError, or of a custom provider's error) withparseProblemDetails(). It maps them to its fields withmapFieldErrors()and shows each message under its control (errorof input, textarea and select).A field is mapped only if the form can send it in its current state: the new-type fields only with "Add new service type", the timestamps only for admins, and the custom ID (
parameter: serviceId) only when one is sent. Errors of a listed type's parts (e.g.#/type/version) show at the type list.Errors of the custom ID and the timestamps open "Advanced Configuration", so they aren't hidden.
A field's error is cleared when:
adminis turned off (custom ID and timestamps);All errors are cleared on Reset, on the next submit (also when the provider can't create) and after a successful create.
If fields change, or the form is reset, while a create runs, the form doesn't show the errors of those fields (and none after a reset). Each create has its own token for this. The event's
fieldErrorsstill holds all of them.ecc-service-create-failedgets two new fields:fieldErrors: a message per field, keyed by the field's path in the request body (e.g.organization.url, andserviceIdfor the custom ID).generalError: the message for the app to show. That iserrorif there are no field errors, else the errors that match no field, orundefined.erroris unchanged, so existing apps keep working.No validation rules were added to the component: the registry has the final say.
Docs: a "Field errors" section and the new event fields on the component page, and a paragraph on field errors in the providers' Errors section. Changeset:
@elixir-cloud/cloud-registryminor.Based on
dev, not on #581. The only overlap with #578/#581 is the providers' docs page, where this PR adds a paragraph after the Errors example and leaves the table alone.CloudRegistryError(errors.ts), which #578 changes, isn't touched.Verification
packages/ecc-client-elixir-cloud-registry/src/components/service-create/tests/service-create-field-errors.test.tsfailed againstdev's component, e.g.expected '' to equal 'Must be at most 3 characters long.'.expected 'Too long.' to equal ''. All of them pass now.errors, non-JSON bodies, new and listed types, and the admin fields together with the opening of their section.adminoff and a dropped environment.npx web-test-runner --config ../../web-test.runner-config.mjs --port 8102inpackages/ecc-client-elixir-cloud-registry: 314 tests passed in Chromium and 314 in Firefox. WebKit isn't installed locally, so CI covers it.npm run lint(turbo; includes the builds of all packages and the docs site): passes, 21/21 tasks. The test file has onlyno-non-null-assertionwarnings, as the other tests do.dev, with no conflicts.656c565: all checks passed: Lint, Test on Node 22 and 24 incl. WebKit, CodeQL, Codecov patch and project, Read the Docs, andCI passed.Review
The
adversarial-reviewerandquality-reviewersubagents reviewed the branch in two rounds.All six Sourcery threads are answered: five are fixed and one is declined (see below). A review by anuragxxd is requested.
Declined review findings
generalError. A field is mapped only if the form can send it in its current state (the new type's parts, the admin fields, the custom ID). An optional field left blank is still a field of the form. If the registry reports it (e.g. an environment it requires), the field is where the user fixes it. The docs now say so.fieldLocations,ADMIN_FIELDSand the type keys. This refactor goes beyond this issue, and tests cover each field's key.failureDetail. They stay, becausemapFieldErrorsneeds the locations.fieldErrorsoptional in the event type. The component always sets it, and apps only read the event. An optional field would make every reader handleundefined.Open questions
None.
Closes #536
🤖 Generated with Claude Code
Summary by Sourcery
Show Cloud Registry validation errors at their corresponding service creation form fields and provide structured failure details for applications.
New Features:
fieldErrorsand a deduplicatedgeneralErrorthrough theecc-service-create-failedevent while preserving the existing error field.Bug Fixes:
Enhancements:
Documentation:
Tests: