fix: log recovered panic in safeGLibType instead of silencing it
- commit
- 30e77be245bccd60e9a1458167a9ce7e7fb053f6
- author
- brice · · 2026-03-06 06:03 UTC
- parent
- 9803305
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
1 file · +7 -3
M internal/infrastructure/webkit/webview.go +7 -3
| @@ -1092,12 +1092,12 @@ const ( | |||
| 1092 | 1092 | ) | |
| 1093 | 1093 | ||
| 1094 | 1094 | func detectPermissionRequestKind(ctx context.Context, requestPtr uintptr) permissionRequestKind { | |
| 1095 | - | if gtype, ok := safeGLibType(webkit.UserMediaPermissionRequestGLibType); ok { | |
| 1095 | + | if gtype, ok := safeGLibType(ctx, webkit.UserMediaPermissionRequestGLibType); ok { | |
| 1096 | 1096 | if isPermissionRequestType(ctx, requestPtr, gtype) { | |
| 1097 | 1097 | return permissionRequestKindUserMedia | |
| 1098 | 1098 | } | |
| 1099 | 1099 | } | |
| 1100 | - | if gtype, ok := safeGLibType(webkit.DeviceInfoPermissionRequestGLibType); ok { | |
| 1100 | + | if gtype, ok := safeGLibType(ctx, webkit.DeviceInfoPermissionRequestGLibType); ok { | |
| 1101 | 1101 | if isPermissionRequestType(ctx, requestPtr, gtype) { | |
| 1102 | 1102 | return permissionRequestKindDeviceInfo | |
| 1103 | 1103 | } | |
| @@ -1108,9 +1108,13 @@ func detectPermissionRequestKind(ctx context.Context, requestPtr uintptr) permis | |||
| 1108 | 1108 | // safeGLibType calls a GType accessor function, recovering from panics caused | |
| 1109 | 1109 | // by unregistered (nil) puregotk function pointers. Returns the GType and true | |
| 1110 | 1110 | // on success, or zero and false if the call panicked. | |
| 1111 | - | func safeGLibType(fn func() gtypes.GType) (gtype gtypes.GType, ok bool) { | |
| 1111 | + | func safeGLibType(ctx context.Context, fn func() gtypes.GType) (gtype gtypes.GType, ok bool) { | |
| 1112 | 1112 | defer func() { | |
| 1113 | 1113 | if r := recover(); r != nil { | |
| 1114 | + | logging.FromContext(ctx).Warn(). | |
| 1115 | + | Str("component", "permission"). | |
| 1116 | + | Interface("panic", r). | |
| 1117 | + | Msg("GType accessor panicked (unregistered puregotk binding?)") | |
| 1114 | 1118 | gtype = 0 | |
| 1115 | 1119 | ok = false | |
| 1116 | 1120 | } | |
| @@ -1092,12 +1092,12 @@ const ( | |||||
| 1092 | ) | 1092 | ) | ||
| 1093 | 1093 | ||||
| 1094 | func detectPermissionRequestKind(ctx context.Context, requestPtr uintptr) permissionRequestKind { | 1094 | func detectPermissionRequestKind(ctx context.Context, requestPtr uintptr) permissionRequestKind { | ||
| 1095 | - | if gtype, ok := safeGLibType(webkit.UserMediaPermissionRequestGLibType); ok { | 1095 | + | if gtype, ok := safeGLibType(ctx, webkit.UserMediaPermissionRequestGLibType); ok { |
| 1096 | if isPermissionRequestType(ctx, requestPtr, gtype) { | 1096 | if isPermissionRequestType(ctx, requestPtr, gtype) { | ||
| 1097 | return permissionRequestKindUserMedia | 1097 | return permissionRequestKindUserMedia | ||
| 1098 | } | 1098 | } | ||
| 1099 | } | 1099 | } | ||
| 1100 | - | if gtype, ok := safeGLibType(webkit.DeviceInfoPermissionRequestGLibType); ok { | 1100 | + | if gtype, ok := safeGLibType(ctx, webkit.DeviceInfoPermissionRequestGLibType); ok { |
| 1101 | if isPermissionRequestType(ctx, requestPtr, gtype) { | 1101 | if isPermissionRequestType(ctx, requestPtr, gtype) { | ||
| 1102 | return permissionRequestKindDeviceInfo | 1102 | return permissionRequestKindDeviceInfo | ||
| 1103 | } | 1103 | } | ||
| @@ -1108,9 +1108,13 @@ func detectPermissionRequestKind(ctx context.Context, requestPtr uintptr) permis | |||||
| 1108 | // safeGLibType calls a GType accessor function, recovering from panics caused | 1108 | // safeGLibType calls a GType accessor function, recovering from panics caused | ||
| 1109 | // by unregistered (nil) puregotk function pointers. Returns the GType and true | 1109 | // by unregistered (nil) puregotk function pointers. Returns the GType and true | ||
| 1110 | // on success, or zero and false if the call panicked. | 1110 | // on success, or zero and false if the call panicked. | ||
| 1111 | - | func safeGLibType(fn func() gtypes.GType) (gtype gtypes.GType, ok bool) { | 1111 | + | func safeGLibType(ctx context.Context, fn func() gtypes.GType) (gtype gtypes.GType, ok bool) { |
| 1112 | defer func() { | 1112 | defer func() { | ||
| 1113 | if r := recover(); r != nil { | 1113 | if r := recover(); r != nil { | ||
| 1114 | + | logging.FromContext(ctx).Warn(). | |||
| 1115 | + | Str("component", "permission"). | |||
| 1116 | + | Interface("panic", r). | |||
| 1117 | + | Msg("GType accessor panicked (unregistered puregotk binding?)") | |||
| 1114 | gtype = 0 | 1118 | gtype = 0 | ||
| 1115 | ok = false | 1119 | ok = false | ||
| 1116 | } | 1120 | } | ||