Skip to content
Flow-UILive
On this page

Decode diagnostics in production

Surface DecodeDiagnostics in debug overlays and logs. A malformed widget should be a telemetry event, not a blank screen.

Ayush MishraPublished 6 min read

Decode diagnostics in production SDUI are how you keep a page alive when the payload is wrong. Unknown types, malformed widgets, dropped array elements, and duplicate ids are recorded with a coding path. The rest of the page still renders. A malformed widget should be a telemetry event, not a blank page.

Flow-UI's promise in resilience is that one bad widget never blanks the page. This post is the operational half: DecodeDiagnostics as data, FlowDebugOverlay while you develop, and how a host should log the same entries in TestFlight and App Store builds without shipping the overlay.

What gets recorded#

DecodeDiagnostics is a class in FlowCore. It is @unchecked Sendable with an internal lock. Each Entry has a kind, optional widget type, coding path string, and message.

KindMeaning
unknownTypeThe widget type string has no registered content model
malformedPayloadThe type is registered but its payload failed to decode
droppedElementAn array element could not be decoded at all and was dropped
duplicateIDTwo widgets claimed the same id; the later one was renamed

Messages are readable on purpose: Missing key 'title' at page.sections.Index 0.widgets.Index 3.data. describeDecodingError turns a DecodingError into that line, including key-not-found, type mismatch, null-where-value, and corrupted data.

PageStore owns the diagnostics instance for the latest decode. Refresh replaces it. Views observe the store; the overlay reads store.diagnostics.entries.

Unknown types also follow UnknownWidgetPolicy: labelled placeholder in debug by default, skip in release by default. Diagnostics still record the type either way. Release users should not see an orange placeholder on a merchandising row. Your telemetry should still see unknownType.

LogDecodeProblems.swiftswift
import FlowCore
import FlowRender
 
func logPageProblems(_ store: PageStore) {
    for entry in store.diagnostics.entries {
        logger.warning(
            "sdui_decode",
            metadata: [
                "kind": "\(entry.kind.rawValue)",
                "widget_type": "\(entry.widgetType ?? "")",
                "path": "\(entry.codingPath)",
                "message": "\(entry.message)",
                "page_id": "\(store.pageID)",
            ]
        )
    }
}

Call that after a successful load, not only after State.failed. A loaded page can still contain five recorded problems. State.failed is for loader or whole-document failure. Widget problems are lossy by design.

swift
if case .loaded = store.state {
    logPageProblems(store)
}

The debug overlay is a debug tool#

flowDebugOverlay(store:) attaches the in-app console. Debug builds get a floating bug button labelled "Flow-UI debug console". It opens a panel with three tools:

  1. Diagnostics. Kind, widget type, message, coding path. Empty state: "The last decode was clean."
  2. Actions. What fired, who handled it, source widget id. Unhandled actions render as a warning in that list.
  3. Inspector. Toggle outlines every widget with its type and id so you can match pixels to JSON.

Release builds compile the modifier to the unmodified view. Do not #if DEBUG around your telemetry. The overlay is gone in release; DecodeDiagnostics is not.

Do not treat the overlay as a production support UI. It is compiled out. If a retailer needs a "what's wrong with this page" tool in a store build, that is a host feature you write against store.diagnostics, with your own auth and redaction.

How to hang it on a page#

DebugHost.swiftswift
FlowPageView(store: store)
    .flowDebugOverlay(store: store)

UIKit: wrap the same FlowPageView inside FlowHostingController, then the overlay still attaches in SwiftUI land. The hosting controller does not include the overlay by default. Add it if you want the ladybug on UIKit-hosted pages during development.

Production telemetry without leaking payloads#

Log kind, type, path, message, page id, app version, and a schema version if your host sends one. Flow-UI does not invent a built-in version header. Additive JSON is the compatibility rule; unknown types skip on old binaries.

Do not log full page documents from production by default. They contain copy, images, and sometimes personalisation. Sample, or log only when entries is non-empty, or gate on a host flag.

Alert on rates, not on a single unknown type. A new widget rolling out to old binaries will produce unknownType until those binaries age out. That is expected. A spike of malformedPayload on a type you shipped last week is a CMS or backend bug: missing required key, wrong shape, null in a non-optional field.

droppedElement on button_row means one malformed button did not empty the row. That is the LossyArray contract. The row still renders; the missing button is still a bug.

duplicateID means mutations and ForEach identity are now ambiguous even though the later widget was renamed (cart_row then cart_row#2). Fix the backend ids. Do not rely on the suffix.

Loaded is not the same as clean#

PageStore.State.failed is for the loader throwing or the whole document failing to decode. Teams alert on failed and ignore loaded with a full diagnostics array. That is how a merchandising row vanishes on Friday night with no ticket.

After every transition to loaded, read store.diagnostics.isEmpty. If it is false, you had a partial success. Partial success is the SDUI default. Treat it like a 206 in HTTP: the page is up, something is missing.

UnknownWidgetPolicy defaults to .placeholder in debug and .skip in release. Changing release to .placeholder will show labelled boxes to customers. Changing debug to .skip will hide the problem you are trying to fix. Leave the defaults unless you have a host reason.

Duplicate ids are renamed so ForEach still works. Mutations that target the original id may hit the wrong row. If you use replace_widget, stable ids are not optional polish.

Overlay versus logs#

The overlay is a debugger. The log is an archive. Do not make on-call read a screenshot of the ladybug panel. Emit structured fields your query language can group: kind, widget_type, page_id, app_version. Then you can chart malformedPayload by type after a CMS change.

Action log in the overlay is debug-only on the dispatcher. Production "unhandled deeplink" belongs in your handler, which should return false so the next handler can try, and log when the chain ends unhandled. That is not DecodeDiagnostics. Do not mix the two streams.

Make it a test, not a rumour#

FlowCore has no SwiftUI import. Fixture tests can decode a payload and assert on diagnostics.entries. That is cheaper than a UI test that looks for a blank page.

Keep a "resilience" fixture that matches the docs: unknown type, missing key, typeless widget, healthy neighbours. Assert two healthy widgets, the recorded kinds, and that decode did not throw.

The playground on this docs site shows a diagnostics list under the JSON editor. The examples page has a resilience preset that is the same idea. Use it to reproduce a CMS bug before you file it. It is not the iOS Simulator and it is not the Swift demo app.

The Flow-UI mark: two nodes joined through a filled centre

Decode diagnostics in production: DecodeDiagnostics on the store, overlay in debug, logs in release. The page stays up. The path in the entry is how you fix the JSON.

More on the blog.

Read the source

Flow-UI is MIT licensed. The schema, renderer and starter widgets live on GitHub.

GitHub

Get started with Flow-UI

Install the Swift package, register a widget, and render a page from JSON.

Get started