also looking at this
fix(ios): preserve specific protocol errors during dispatch
#303
3 files
+51
-11
| @@ -194,17 +194,16 @@ pub fn errorMessage(err: BridgeError) []const u8 { | ||
| 194 | 194 | /// the dispatcher exposes. Errors the protocol cannot name become the honest |
| 195 | 195 | /// catch-all instead of leaving the page without a reply. |
| 196 | 196 | pub fn fromHandlerError(err: anyerror) BridgeError { |
| 197 | // Preserve every explicitly declared protocol error before translating | |
| 198 | // implementation aliases. A hand-maintained subset loses useful errors | |
| 199 | // (for example WebViewHandleNotSet) when new handlers start returning them. | |
| 200 | inline for (@typeInfo(BridgeError).error_set.error_names.?) |name| { | |
| 201 | const protocol_error = @field(BridgeError, name); | |
| 202 | if (err == protocol_error) return protocol_error; | |
| 203 | } | |
| 197 | 204 | return switch (err) { |
| 198 | error.AllocationFailed, error.OutOfMemory => BridgeError.AllocationFailed, | |
| 199 | error.UnknownAction => BridgeError.UnknownAction, | |
| 200 | error.MissingData => BridgeError.MissingData, | |
| 201 | error.InvalidJSON => BridgeError.InvalidJSON, | |
| 202 | error.InvalidParameter => BridgeError.InvalidParameter, | |
| 203 | error.Busy => BridgeError.Busy, | |
| 204 | error.PlatformNotSupported, error.UnsupportedPlatform => BridgeError.PlatformNotSupported, | |
| 205 | error.NotFound => BridgeError.NotFound, | |
| 206 | error.PermissionDenied => BridgeError.PermissionDenied, | |
| 207 | error.Timeout => BridgeError.Timeout, | |
| 205 | error.OutOfMemory => BridgeError.AllocationFailed, | |
| 206 | error.UnsupportedPlatform => BridgeError.PlatformNotSupported, | |
| 208 | 207 | else => BridgeError.NativeCallFailed, |
| 209 | 208 | }; |
| 210 | 209 | } |
| @@ -379,7 +378,10 @@ test "errorCodeString returns correct codes" { | ||
| 379 | 378 | |
| 380 | 379 | test "handler error narrowing preserves protocol errors" { |
| 381 | 380 | const testing = std.testing; |
| 382 | try testing.expectEqual(BridgeError.Busy, fromHandlerError(error.Busy)); | |
| 381 | inline for (@typeInfo(BridgeError).error_set.error_names.?) |name| { | |
| 382 | const protocol_error = @field(BridgeError, name); | |
| 383 | try testing.expectEqual(protocol_error, fromHandlerError(protocol_error)); | |
| 384 | } | |
| 383 | 385 | try testing.expectEqual(BridgeError.PlatformNotSupported, fromHandlerError(error.UnsupportedPlatform)); |
| 384 | 386 | try testing.expectEqual(BridgeError.AllocationFailed, fromHandlerError(error.OutOfMemory)); |
| 385 | 387 | try testing.expectEqual(BridgeError.NativeCallFailed, fromHandlerError(error.NotInTheProtocol)); |