refactor(ios): safely(tag:default:) wrapper for the catch-log-and-default band-aid#660
Merged
Merged
Conversation
Size Report
Startup median (7 runs, lower is better):
Top changed chunks: no changes in the largest emitted chunks. |
…ault band-aid
Consolidate the repeated `var x = default; catchException({ x = expr }); if let m {
NSLog("..._IGNORED_EXCEPTION=%@", m); return default }; return x` shape used around
exception-prone XCUITest queries into one generic helper (RunnerTests+Exceptions.swift):
func safely<T>(_ tag:, _ fallback:, _ block:) -> T
func safely<T>(_ tag:, _ block: () -> T?) -> T? // nil-default convenience
11 uniform sites adopt it: SystemModal (4), Snapshot (2), TextEntry (2), Interaction (3).
Each drops from ~7-12 lines to 1-3. The NSLog format is preserved byte-for-byte via the tag arg
(tag "MODAL_QUERY" -> "AGENT_DEVICE_RUNNER_MODAL_QUERY_IGNORED_EXCEPTION=%@"), so the
silently-logged-and-continued path keeps its searchable format and now has a single place to add
per-tag exception telemetry.
Left inline by design (not the uniform pattern): the silent `_ = catchException` KVC reads
(elementHasFocus, snapshotHasFocus), the throw-on-AX snapshot path, executeOnMainSafely's
retry-driving catch, and the bespoke pressKeyboardReturn fallback / performElementTap branches
whose result depends on the exception message.
Behavior-preserving: same defaults, same log output, same returned values. catchException is
non-escaping, so the inout capture in safeIsActionableCandidate is preserved.
Verified: xcodebuild build-for-testing -> TEST BUILD SUCCEEDED.
1014dce to
d3a50ee
Compare
Member
Author
Verified on-device ✅Ran The replay drives pinch/rotate/pan/fling and the snapshot + element-query + keyboard-frame paths (via its Re: reviewThanks — all findings are low/optional and I agree:
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Consolidate the runner's repeated catch-log-and-default band-aid into one generic helper (
RunnerTests+Exceptions.swift):11 uniform sites adopt it — SystemModal (4), Snapshot (2), TextEntry (2), Interaction (3). Each
var x = default; catchException({ x = … }); if let m { NSLog("…_IGNORED_EXCEPTION=%@", m); return default }; return xshrinks to a singlesafely("TAG", default) { … }.Why
20
catchExceptionsites across the runner; ~15 followed the same silent-log-and-continue shape, copy-pasted with a per-site tag. One helper removes the drift, and gives the "silently logged and continued" path a single instrumentation point (per-tag exception-rate telemetry later).Safety
tag "MODAL_QUERY"→AGENT_DEVICE_RUNNER_MODAL_QUERY_IGNORED_EXCEPTION=%@).RunnerObjCExceptionCatcher.catchExceptionis non-escaping, soblockcan still captureinoutstate (e.g.safeIsActionableCandidate'sseen)._ = catchExceptionKVC reads (elementHasFocus,snapshotHasFocus), the throw-on-AX snapshot path,executeOnMainSafely's retry-driving catch, and the bespokepressKeyboardReturnfallback /performElementTapbranches whose result depends on the exception message.xcodebuild build-for-testing→ TEST BUILD SUCCEEDED.Scope
Candidate ② from the post-merge refactor re-scan. Independent of #659 (that's
CommandExecution-only; this leaves the oneCommandExecutioncatch — the retry driver — untouched). New file auto-included via the file-system-synchronized group.