Commit daaf71a
authored
refactor(ios): safely(tag:default:) wrapper for the catch-log-and-default band-aid (#660)
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.1 parent 3f65124 commit daaf71a
5 files changed
Lines changed: 52 additions & 127 deletions
File tree
- ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests
Lines changed: 29 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
Lines changed: 8 additions & 34 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
285 | 285 | | |
286 | 286 | | |
287 | 287 | | |
288 | | - | |
289 | | - | |
| 288 | + | |
290 | 289 | | |
291 | 290 | | |
292 | 291 | | |
293 | 292 | | |
294 | 293 | | |
295 | | - | |
| 294 | + | |
296 | 295 | | |
297 | 296 | | |
298 | 297 | | |
| |||
318 | 317 | | |
319 | 318 | | |
320 | 319 | | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | 320 | | |
329 | | - | |
330 | 321 | | |
331 | 322 | | |
332 | 323 | | |
| |||
431 | 422 | | |
432 | 423 | | |
433 | 424 | | |
434 | | - | |
435 | | - | |
436 | | - | |
| 425 | + | |
| 426 | + | |
437 | 427 | | |
438 | 428 | | |
439 | 429 | | |
| |||
442 | 432 | | |
443 | 433 | | |
444 | 434 | | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | | - | |
451 | | - | |
452 | 435 | | |
453 | 436 | | |
454 | 437 | | |
| |||
784 | 767 | | |
785 | 768 | | |
786 | 769 | | |
787 | | - | |
788 | | - | |
| 770 | + | |
789 | 771 | | |
790 | | - | |
| 772 | + | |
791 | 773 | | |
792 | | - | |
793 | | - | |
794 | | - | |
795 | | - | |
796 | | - | |
797 | | - | |
798 | | - | |
799 | | - | |
800 | | - | |
| 774 | + | |
| 775 | + | |
801 | 776 | | |
802 | | - | |
803 | 777 | | |
804 | 778 | | |
805 | 779 | | |
| |||
Lines changed: 2 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
354 | 354 | | |
355 | 355 | | |
356 | 356 | | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
| 357 | + | |
365 | 358 | | |
366 | 359 | | |
367 | 360 | | |
| |||
718 | 711 | | |
719 | 712 | | |
720 | 713 | | |
721 | | - | |
722 | | - | |
723 | | - | |
724 | | - | |
725 | | - | |
726 | | - | |
727 | | - | |
728 | | - | |
729 | | - | |
730 | | - | |
731 | | - | |
732 | | - | |
| 714 | + | |
733 | 715 | | |
734 | 716 | | |
735 | 717 | | |
| |||
Lines changed: 10 additions & 50 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
| 80 | + | |
92 | 81 | | |
93 | 82 | | |
94 | 83 | | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
| 84 | + | |
107 | 85 | | |
108 | 86 | | |
109 | 87 | | |
| |||
134 | 112 | | |
135 | 113 | | |
136 | 114 | | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
141 | 118 | | |
142 | | - | |
| 119 | + | |
143 | 120 | | |
144 | | - | |
| 121 | + | |
145 | 122 | | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
| 123 | + | |
154 | 124 | | |
155 | | - | |
156 | 125 | | |
157 | 126 | | |
158 | 127 | | |
| |||
205 | 174 | | |
206 | 175 | | |
207 | 176 | | |
208 | | - | |
209 | | - | |
210 | | - | |
| 177 | + | |
| 178 | + | |
211 | 179 | | |
212 | 180 | | |
213 | 181 | | |
| |||
216 | 184 | | |
217 | 185 | | |
218 | 186 | | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | 187 | | |
227 | | - | |
228 | 188 | | |
229 | 189 | | |
Lines changed: 3 additions & 23 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | | - | |
77 | | - | |
| 76 | + | |
78 | 77 | | |
79 | 78 | | |
80 | 79 | | |
81 | 80 | | |
82 | 81 | | |
83 | 82 | | |
84 | 83 | | |
85 | | - | |
86 | | - | |
| 84 | + | |
87 | 85 | | |
88 | 86 | | |
89 | 87 | | |
90 | 88 | | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | 89 | | |
98 | 90 | | |
99 | | - | |
100 | 91 | | |
101 | 92 | | |
102 | 93 | | |
| |||
650 | 641 | | |
651 | 642 | | |
652 | 643 | | |
653 | | - | |
654 | | - | |
655 | | - | |
656 | | - | |
657 | | - | |
658 | | - | |
659 | | - | |
660 | | - | |
661 | | - | |
662 | | - | |
663 | | - | |
664 | | - | |
| 644 | + | |
665 | 645 | | |
666 | 646 | | |
667 | 647 | | |
| |||
0 commit comments