namespace ZB.MOM.WW.OtOpcUa.Tests; internal static class FixtureCleanup { internal const string SecondaryExceptionKey = "FixtureCleanup.SecondaryException"; internal static async Task RunAsync(Func body, Func cleanup, Action report) { Exception? primary = null; try { await body(); } catch (Exception failure) { primary = failure; throw; } finally { try { await cleanup(); } catch (Exception secondary) when (primary is not null) { try { primary.Data[SecondaryExceptionKey] = secondary; } catch { } try { report(secondary); } catch { } } } } }