Skip to content

feat(cloud-registry): expose problem details - #504

Merged
anuragxxd merged 6 commits into
devfrom
feat/cr-problem-details
Oct 31, 2026
Merged

anuragxxd merged 6 commits into
devfrom
feat/cr-problem-details

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Description

RestCloudRegistryProvider threw plain errors built from response.statusText (empty over HTTP/2, so messages read "Failed to create service: ") and never read the body. Apps couldn't tell 401 (log in) from 403 (no role on the service), and the create component's users didn't learn why a registration failed, although the registry explains every error as problem details. The Cloud Registry UI works around this in its own provider and by wrapping the provider on its create page to recover the error behind ecc-service-create-failed.

  • CloudRegistryError (exported from @elixir-cloud/cloud-registry/providers, with the ProblemDetails type): extends Error and has status, title, detail, serviceId and problem (the whole JSON body). Every method of RestCloudRegistryProvider throws it for error statuses. The body is read whatever its content type (also application/problem+json; proxies may send HTML). The message is the problem's detail, else a message field, else the action and the status, e.g. "Failed to create service (502)". Blank fields count as missing. Error bodies are read only up to 64 KiB (MAX_PROBLEM_BYTES) and for at most 5 s (PROBLEM_TIMEOUT_MS), so a huge or stalled body from a proxy can't hold up the error.
  • ecc-service-create-failed now also carries status, title, detail, serviceId and cause (the thrown error), next to error. They are read from the error's fields, so custom providers that throw errors with these fields (as the Cloud Registry UI's does) work too. Thrown strings and plain objects with detail/message give a useful error as well.
  • Behaviour change: when the service types can't be loaded, error was the fixed "Failed to load service types"; it is now "Failed to load service types: " (the reason if there is one), with the status and problem details. Code that compares the whole string must check its start instead.
  • providers/index.ts exports the CloudRegistryProvider interface with export type; as a value export, browsers loading the unbundled modules (the tests) fail to import the module. No change for bundled consumers, since it is an interface.
  • Docs: an "Errors" section on the Cloud Registry providers page, and the event's fields on the create component's page.
  • Tests: the error of every provider method, 401 vs 403, the fallbacks (no JSON, message, blank and wrongly typed fields, status text), and the event for CloudRegistryErrors, custom errors, strings, plain objects and failed type loads, plus too large and stalled error bodies (23 cases). Adds the package's test script and the tsconfig option of the shared test config, as fix(cloud-registry): react to provider changes #502 and feat: add surface, font and dark mode controls #446 do.

Closes #454

How it was verified

  • npm run lint: 0 errors (warnings unchanged).
  • npm run build (cloud-registry and dependencies, and the docs site).
  • npx web-test-runner --group default in packages/ecc-client-elixir-cloud-registry with Chromium and Firefox: 23/23 pass; wes tests still pass with the changed shared config. WebKit can't start on my machine; CI runs it.
  • CI: all checks pass; the cloud-registry tests pass in Chromium, Firefox and WebKit. The first run failed because the cloud-registry and wes test runners both used port 8000 in parallel; the package now uses --port 8002 (also in fix(cloud-registry): react to provider changes #502). After the Sourcery fix (bounded body reader), CI passed again.

Checklist

  • My code follows the contributing guidelines of this project.
  • I am aware that all my commits will be squashed into a single commit, using the PR title as the commit message.
  • I have performed a self-review of my own code.
  • I have commented my code in hard-to-understand areas.
  • I have updated the user-facing documentation to describe any new or changed behavior.
  • My changes generate no new warnings.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have not reduced the existing code coverage.

Comments

Declined review findings

  • No separate field (e.g. action) to tell a failed type load from a failed registration: the prefix of error tells them apart, and the event already exists for both cases. Easy to add if you prefer a field.
  • A proxy error without a body during the type load reads "Failed to load service types: Failed to fetch service types (502)": slightly redundant, but correct.
  • The shared test config's tsconfig: "./tsconfig.json" is relative to the working directory, so tests must run from a package directory (as all test scripts do); documented in a comment.
  • Success responses with non-JSON bodies (e.g. a 204 on delete) still reject with a SyntaxError: older than this branch, not part of feat(cloud-registry): expose problem details on errors #454.

🤖 Generated with Claude Code

Summary by Sourcery

Expose structured Cloud Registry errors and propagate actionable problem details through service creation failure events.

New Features:

  • Expose structured Cloud Registry problem details through the REST provider with the exported CloudRegistryError and ProblemDetails types.
  • Include HTTP status and problem metadata in ecc-service-create-failed events for registration and service-type loading failures.

Bug Fixes:

  • Replace unreliable status-text-only errors with useful messages derived from registry responses, including safe fallbacks for malformed, oversized, stalled, or non-JSON bodies.

Enhancements:

  • Support custom provider errors, thrown strings, and plain objects while preserving their useful details in create failure events.
  • Export the provider interface as a type-only export for compatibility with unbundled browser modules.

CI:

  • Update the shared web test runner configuration for package-local TypeScript configuration.

Documentation:

  • Document Cloud Registry provider errors and the expanded service-create failure event fields.

Tests:

  • Add coverage for structured errors across all REST provider methods, HTTP status distinctions, fallback messages, bounded error-body handling, and component failure events.

uniqueg and others added 2 commits October 28, 2026 20:36
RestCloudRegistryProvider threw plain errors built from statusText,
which is empty over HTTP/2, and never read the body. Apps couldn't tell
401 from 403, and users didn't learn why a registration failed.

- Add CloudRegistryError (status, title, detail, serviceId, problem),
  thrown by every provider method, with the problem's detail (else the
  body's message, else the action and status) as the message.
- ecc-service-create-failed now also carries status, title, detail,
  serviceId and the thrown error (cause), read from the error's fields,
  so custom providers' errors work too; also when the service types
  can't be loaded.
- Export the CloudRegistryProvider interface as a type, so the
  providers module loads in unbundled ES modules (tests).
- Document the errors and the event detail; add tests.

Closes #454

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Skip blank fields, leave the status text out of fallback messages
(HTTP/2 has none), share the field check with the component, read
the explanation of plain objects and strings, and prefix failures to
load the service types with that action. Add tests and comments.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

This PR replaces opaque REST status-text errors with exported structured CloudRegistryError instances, propagates their problem details through service-create failure events, and adds corresponding documentation, regression coverage, and test-runner configuration.

Sequence diagram for structured Cloud Registry errors

sequenceDiagram
    participant Client
    participant RestProvider
    participant Registry
    participant CloudRegistryError

    Client->>RestProvider: createService(service)
    RestProvider->>Registry: POST /services
    Registry-->>RestProvider: Error response with status and problem body
    RestProvider->>CloudRegistryError: fromResponse(response, action)
    CloudRegistryError->>CloudRegistryError: response.json()
    CloudRegistryError-->>RestProvider: CloudRegistryError
    RestProvider-->>Client: reject with status, detail, title, serviceId, problem
Loading

Sequence diagram for service-create failure event details

sequenceDiagram
    participant User
    participant ServiceCreate
    participant Provider
    participant Registry

    User->>ServiceCreate: Submit service
    ServiceCreate->>Provider: createService(service)
    Provider->>Registry: POST /services
    Registry-->>Provider: 401, 403, 409, or other error
    Provider-->>ServiceCreate: throw error with problem fields
    ServiceCreate->>ServiceCreate: failureDetail(error, action)
    ServiceCreate-->>User: ecc-service-create-failed with error, status, detail, title, serviceId, cause
Loading

File-Level Changes

Change Details Files
Introduces structured Cloud Registry request errors with RFC problem-details extraction and consistent fallbacks.
  • Adds exported CloudRegistryError and ProblemDetails types.
  • Reads JSON error bodies regardless of content type and preserves status, title, detail, service ID, and full problem body.
  • Updates every REST provider method to reject with the structured error, including status-based fallback messages.
  • Exports the provider interface as a type-only export for unbundled browser/test compatibility.
packages/ecc-client-elixir-cloud-registry/src/providers/errors.ts
packages/ecc-client-elixir-cloud-registry/src/providers/index.ts
packages/ecc-client-elixir-cloud-registry/src/providers/rest-cr-provider.ts
Extends service-create failure events to expose structured provider error information and robustly handle arbitrary thrown values.
  • Normalizes Error, strings, plain objects, blank fields, and invalid field types into event details.
  • Includes status, title, detail, serviceId, and the original cause.
  • Adds the same metadata to service-type loading failures and prefixes their user-facing message with the loading action.
packages/ecc-client-elixir-cloud-registry/src/components/service-create/service-create.ts
packages/ecc-client-elixir-cloud-registry/src/events/ecc-service-create-failed.ts
Documents and tests the new error contract across provider methods and the service-create component.
  • Documents CloudRegistryError, event fields, authentication/authorization distinctions, and duplicate-service handling.
  • Covers all provider methods, response-body fallbacks, malformed fields, blank details, 401/403 statuses, custom errors, strings, plain objects, and failed type loads.
  • Adds the package test script and configures the shared test runner with the package TypeScript configuration and dedicated port.
apps/documentation/pages/docs/cloud-registry/providers.mdx
apps/documentation/pages/docs/cloud-registry/components/service-create.mdx
packages/ecc-client-elixir-cloud-registry/src/providers/tests/rest-cr-provider.test.ts
packages/ecc-client-elixir-cloud-registry/src/components/service-create/tests/service-create-errors.test.ts
packages/ecc-client-elixir-cloud-registry/package.json
web-test.runner-config.mjs

Assessment against linked issues

Issue Objective Addressed Explanation
#454 Make every failed RestCloudRegistryProvider request expose its HTTP status and problem details through an exported error class, using the registry's detail or message as the error message and a useful status-based fallback when the body is missing or unusable. ✅
#454 Propagate the registry's explanation and available status and problem fields through the service-create failure event so registration failures are informative to component users. ✅

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@read-the-docs-community

read-the-docs-community Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Turbo runs the packages' tests in parallel, and the wes tests use the
default port 8000, so the second runner failed with EADDRINUSE.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg marked this pull request as ready for review October 28, 2026 22:15
@uniqueg
uniqueg requested a review from anuragxxd as a code owner October 28, 2026 22:15

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

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/providers/errors.ts" line_range="73" />
<code_context>
+  ): Promise<CloudRegistryError> {
+    let problem: ProblemDetails | undefined;
+    try {
+      const body: unknown = await response.json();
+      if (body && typeof body === "object" && !Array.isArray(body)) {
+        problem = body as ProblemDetails;
</code_context>
<issue_to_address>
**Error response bodies can stall failures**

When an upstream or proxy returns an error response whose body is very large or does not finish streaming, `response.json()` reads the entire error body before `fromResponse` returns; a stalled or exceptionally large body therefore keeps provider calls pending or consumes excessive memory, so callers never receive the error and the component never emits its failure event.

Bound error-body reading by size and duration, then fall back to the action-and-status message when a bound is reached.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: packages/ecc-client-elixir-cloud-registry/src/providers/errors.ts:73


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Read at most 64 KiB of an error body within 5 seconds, so that a huge
or stalled body (e.g. from a proxy) cannot hold up the error; fall
back to the action and status otherwise.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
sourcery-ai[bot]
sourcery-ai Bot previously approved these changes Oct 28, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sourcery assessment

Approved.

@uniqueg uniqueg mentioned this pull request Oct 29, 2026
8 tasks done
#504 adds the reason to the error of a failed type load; the test from
#502 still expected the fixed message.

@anuragxxd anuragxxd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Alex. Approving; I'm merging this next, once CI passes.

To save you the rebase after #502, I merged dev into the branch:

  • web-test.runner-config.mjs: the only conflict. I kept your comment that tests must run from the package directory.
  • service-create.ts merged cleanly: #502's check for late answers and your failureDetail() now sit together in the type-loading error branch.
  • 5081045: #502's test "drops the old types if the new provider fails" still expected the fixed message Failed to load service types. It now expects Failed to load service types: unauthorized, the message this PR is meant to produce.

All 34 cloud-registry tests pass locally in Chromium, Firefox and WebKit, and lint and build pass.

@sourcery-ai
sourcery-ai Bot dismissed their stale review October 31, 2026 06:40

Sourcery withdrew this approval because the latest commits introduced blocking findings.

@anuragxxd
anuragxxd merged commit 7c94e3c into dev Oct 31, 2026
12 checks passed
@anuragxxd
anuragxxd deleted the feat/cr-problem-details branch October 31, 2026 06:45
uniqueg added a commit that referenced this pull request Oct 31, 2026
Resolve the conflicts in service-create.ts: keep the type picker and
its type status and reloads, on dev's provider handling (#502) and
problem details (#504); drop the duplicate typesRequest field.

Adapt dev's new service-create tests to the type picker: fillForm
chooses "Add new service type", and the provider tests expect the
reload of the types after a create.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
uniqueg added a commit that referenced this pull request Oct 31, 2026
Resolve the conflicts in service-create.ts and its docs: keep the
validation, environments and URL schemes; dev's provider handling (#502)
now loads the registration rules too, and resets them without a
provider. The event table takes dev's failure details (#504) and the
PR's validation details.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(cloud-registry): expose problem details on errors

2 participants