From 1f2fb3f796617e542c540aca55f65d5abb34c529 Mon Sep 17 00:00:00 2001 From: Federico Maccaroni Date: Thu, 14 Jul 2022 18:54:45 -0300 Subject: [PATCH] [EC-324] Added more logging for information on list crash (#1993) * EC-324 Added more logging for trying to get more information on list out of range crash on AppCenter * EC-324 Fix include on iOS.Core.csproj on iOS CollectionView files --- .../CollectionView/CollectionException.cs | 16 +++++++ .../ExtendedGroupableItemsViewController.cs | 19 +++++++- .../ExtendedGroupableItemsViewDelegator.cs | 43 +++++++++++++++++++ src/iOS.Core/iOS.Core.csproj | 2 + 4 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 src/iOS.Core/Renderers/CollectionView/CollectionException.cs create mode 100644 src/iOS.Core/Renderers/CollectionView/ExtendedGroupableItemsViewDelegator.cs diff --git a/src/iOS.Core/Renderers/CollectionView/CollectionException.cs b/src/iOS.Core/Renderers/CollectionView/CollectionException.cs new file mode 100644 index 000000000..35204bf95 --- /dev/null +++ b/src/iOS.Core/Renderers/CollectionView/CollectionException.cs @@ -0,0 +1,16 @@ +using System; +namespace Bit.iOS.Core.Renderers.CollectionView +{ + public class CollectionException : Exception + { + public CollectionException(string message) + : base(message) + { + } + + public CollectionException(string message, Exception innerEx) + : base(message, innerEx) + { + } + } +} diff --git a/src/iOS.Core/Renderers/CollectionView/ExtendedGroupableItemsViewController.cs b/src/iOS.Core/Renderers/CollectionView/ExtendedGroupableItemsViewController.cs index 94c15e114..519fcbbb6 100644 --- a/src/iOS.Core/Renderers/CollectionView/ExtendedGroupableItemsViewController.cs +++ b/src/iOS.Core/Renderers/CollectionView/ExtendedGroupableItemsViewController.cs @@ -1,6 +1,8 @@ using System; using Bit.App.Controls; +using Bit.Core.Services; using Foundation; +using UIKit; using Xamarin.Forms.Platform.iOS; namespace Bit.iOS.Core.Renderers.CollectionView @@ -13,6 +15,11 @@ namespace Bit.iOS.Core.Renderers.CollectionView { } + protected override UICollectionViewDelegateFlowLayout CreateDelegator() + { + return new ExtendedGroupableItemsViewDelegator>(ItemsViewLayout, this); + } + protected override void UpdateTemplatedCell(TemplatedCell cell, NSIndexPath indexPath) { try @@ -21,7 +28,17 @@ namespace Bit.iOS.Core.Renderers.CollectionView } catch (Exception ex) when (ItemsView?.ExtraDataForLogging != null) { - throw new Exception("Error in ExtendedCollectionView, extra data: " + ItemsView.ExtraDataForLogging, ex); + var colEx = new CollectionException("Error in ExtendedCollectionView -> ExtendedGroupableItemsViewController, extra data: " + ItemsView.ExtraDataForLogging, ex); + try + { + LoggerHelper.LogEvenIfCantBeResolved(colEx); + } + catch + { + // Do nothing in here, this is temporary to get more info about the crash, if the logger fails, we want to get the info + // by crashing with the original exception and not the logger one + } + throw colEx; } } } diff --git a/src/iOS.Core/Renderers/CollectionView/ExtendedGroupableItemsViewDelegator.cs b/src/iOS.Core/Renderers/CollectionView/ExtendedGroupableItemsViewDelegator.cs new file mode 100644 index 000000000..d6ccb30fe --- /dev/null +++ b/src/iOS.Core/Renderers/CollectionView/ExtendedGroupableItemsViewDelegator.cs @@ -0,0 +1,43 @@ +using System; +using Bit.App.Controls; +using Bit.Core.Services; +using CoreGraphics; +using Foundation; +using UIKit; +using Xamarin.Forms.Platform.iOS; + +namespace Bit.iOS.Core.Renderers.CollectionView +{ + public class ExtendedGroupableItemsViewDelegator : GroupableItemsViewDelegator + where TItemsView : ExtendedCollectionView + where TViewController : GroupableItemsViewController + { + public ExtendedGroupableItemsViewDelegator(ItemsViewLayout itemsViewLayout, TViewController itemsViewController) + : base(itemsViewLayout, itemsViewController) + { + } + + public override CGSize GetSizeForItem(UICollectionView collectionView, UICollectionViewLayout layout, NSIndexPath indexPath) + { + // Added this to get extra information on a crash when getting the size for an item. + try + { + return base.GetSizeForItem(collectionView, layout, indexPath); + } + catch (Exception ex) when (ViewController?.ItemsView?.ExtraDataForLogging != null) + { + var colEx = new CollectionException("Error in ExtendedCollectionView -> ExtendedGroupableItemsViewDelegator, extra data: " + ViewController.ItemsView.ExtraDataForLogging, ex); + try + { + LoggerHelper.LogEvenIfCantBeResolved(colEx); + } + catch + { + // Do nothing in here, this is temporary to get more info about the crash, if the logger fails, we want to get the info + // by crashing with the original exception and not the logger one + } + throw colEx; + } + } + } +} diff --git a/src/iOS.Core/iOS.Core.csproj b/src/iOS.Core/iOS.Core.csproj index 4344ddb6d..9cb52e91a 100644 --- a/src/iOS.Core/iOS.Core.csproj +++ b/src/iOS.Core/iOS.Core.csproj @@ -201,6 +201,8 @@ + +