Skip to content

refactor(ios): use wordpress-rs connectivity error helpers - #580

Open
dcalhoun wants to merge 3 commits into
trunkfrom
refactor/ios-use-wprs-error-helpers
Open

refactor(ios): use wordpress-rs connectivity error helpers#580
dcalhoun wants to merge 3 commits into
trunkfrom
refactor/ios-use-wprs-error-helpers

Conversation

@dcalhoun

@dcalhoun dcalhoun commented Aug 6, 2026

Copy link
Copy Markdown
Member

What?

Replaces the iOS demo app's hand-rolled connectivity error classifiers with the equivalents added to wordpress-rs.

Closes #578.

Why?

SitePreparationView matched WpApiError.RequestExecutionFailed with five positional associated values to read a single nested reason — once for "site unreachable", once for "device offline". That is fragile: it breaks whenever WpApiError gains a case, and it duplicates knowledge that belongs to wordpress-rs, which creates the distinction in the first place.

Raised in review feedback on #572: "We should probably lower this into wprs on either the Swift or Rust layers."

How?

Both helpers are deleted and their call sites read the library property directly:

} catch let error as WpApiError where error.isSiteUnreachable {

A typed catch does the cast, so no wrapper is needed — and the demo app no longer defines its own vocabulary for a distinction the library already names.

The error is URLError fallback goes with them. Every throwing call in the enclosing do blocks goes through WordPressAPIapiRoot.get() and postTypes.listWithEditContext() — so WpRequestExecutor has already rewrapped any URLError into a WpApiError by the time these run. The only remaining URLSession reference in the file is the URLSessionConfiguration passed into WordPressAPI, so the fallback could never fire.

Depends on Automattic/wordpress-rs#1488, which adds isSiteUnreachable / isDeviceOffline.

Follow-up: Android

#578 also covers bringing the Android demo app to parity — it currently discards the failure reason in loadPostTypes and substitutes a hardcoded post type, which is why the plain-permalink bug fixed in #572 went unnoticed there. That work is blocked on a wordpress-rs mapping inconsistency: the Kotlin executor maps a refused connection to HttpError while Swift maps it to NonExistentSiteError, so isSiteUnreachable currently answers differently per platform. Details in the "Known limitation" section of #1488.

Testing Instructions

  1. Open ios/Demo-iOS/Gutenberg.xcodeproj and let package resolution finish.
  2. Site unreachable — with wp-env stopped and the network up, open the Local WordPress site. Expect the wp-env guidance: "Could not connect to Local WordPress at localhost:8888…".
  3. Device offline — with a saved account, enable Airplane Mode and open its Editor Configuration. Expect the screen to load with the offline fallback applied: Network Fallback shows "Automatic", Post Type shows "Post", and Site URL shows the stored API root.
  4. The two are distinct — with the network up, block the site's host in /etc/hosts, then open its Editor Configuration. Expect the error view with "A server with the specified hostname could not be found", not the offline fallback. This confirms isSiteUnreachable and isDeviceOffline return opposite answers for the same error.

Verified on device: all three behave as described, and a full xcodebuild of the demo app succeeds.

Accessibility Testing Instructions

N/A — no user interface changes. The error and fallback paths are unchanged; only how they are detected differs.

@dcalhoun dcalhoun added [Type] Code Quality Issues or PRs that relate to code quality iOS labels Aug 6, 2026
@wpmobilebot

wpmobilebot commented Aug 6, 2026

Copy link
Copy Markdown

XCFramework Build

This PR's XCFramework is available for testing. Add the following to your Package.swift:

.package(url: "https://github.com/wordpress-mobile/GutenbergKit", branch: "pr-build/580")

Built from 8767e26

@dcalhoun
dcalhoun force-pushed the refactor/ios-use-wprs-error-helpers branch from b7fec3b to 2bfeb35 Compare August 6, 2026 17:24
@github-actions github-actions Bot added the [Type] Task Issues or PRs that have been broken down into an individual action to take label Aug 6, 2026
@dcalhoun
dcalhoun marked this pull request as ready for review August 6, 2026 20:32
@dcalhoun
dcalhoun requested a review from jkmassel August 6, 2026 20:34
dcalhoun and others added 3 commits August 7, 2026 09:49
Replaces the hand-rolled `WpApiError.RequestExecutionFailed` pattern matches
with `isSiteUnreachable` and `isDeviceOffline`, added in wordpress-rs.

Both call sites now use a typed `catch` and read the library property
directly, so the demo app no longer defines its own vocabulary for this
distinction.

Drops the `error is URLError` fallback along with the helpers. Every throwing
call in the enclosing `do` blocks goes through `WordPressAPI` —
`apiRoot.get()` and `postTypes.listWithEditContext()` — so `WpRequestExecutor`
has already rewrapped any `URLError` into a `WpApiError` by the time these
run. The fallback could never fire.

Refs #578

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Temporarily resolves wordpress-rs from the `pr-build/1488` snapshot branch so
the demo app can build against `WpApiError.isSiteUnreachable` and
`.isDeviceOffline`, which are not in the released 0.6.0.

INTERIM — must be replaced with an exact version before merging. The snapshot
branch is force-pushed on every CI run of Automattic/wordpress-rs#1488 and its
S3 artifact lives under `pr-builds/1488/`, so neither is maintained once that
PR merges. Swap to the release that carries the new API.

Refs #578

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The `pr-build/1488` snapshot branch was deleted once that PR merged, taking
its S3 artifact under `pr-builds/1488/` with it, so the previous pin no
longer resolves.

Repoints at `trunk-build`, the published mirror of trunk. Trunk itself
cannot be consumed as a remote SPM dependency: its `Package.swift` sets
`libwordpressFFIVersion = .local`, which expects
`target/libwordpressFFI.xcframework` to be built locally by Cargo and is
absent from a fresh checkout. `trunk-build` carries the same Swift sources
but declares `.release`, fetching the prebuilt xcframework from the CDN.

Pinned by revision rather than branch because `trunk-build` is force-pushed
on every trunk CI run. `d70c99e1` is the build of trunk `c2f8a25f`, which
carries `WpApiError.isSiteUnreachable` and `.isDeviceOffline`.

INTERIM — must be replaced with an exact version before merging. No tagged
release carries these helpers yet; the latest, `alpha-20260313.1`, predates
Automattic/wordpress-rs#1488. Swap to the release that carries the new API.

Refs #578

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@dcalhoun
dcalhoun force-pushed the refactor/ios-use-wprs-error-helpers branch from 2bfeb35 to 8767e26 Compare August 7, 2026 13:49
Comment on lines +576 to +577
kind = revision;
revision = d70c99e1ff38772353bd8f6a81879320990a560e;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Is it safe to use a wordpress-rs commit hash for the Demo app or do we need to await a tag?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

iOS [Type] Code Quality Issues or PRs that relate to code quality [Type] Task Issues or PRs that have been broken down into an individual action to take

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lower connectivity error classification into wordpress-rs

2 participants