internal static async Task <T> WithErrorTranslationAndProfiling <T>(Func <Task <T> > t, string name, Logger logger) { SpannerException translatedException; try { Stopwatch sw = null; if (logger.LogPerformanceTraces) { sw = Stopwatch.StartNew(); } var result = await t().ConfigureAwait(false); if (sw != null) { logger.LogPerformanceCounterFn($"{name}.Duration", x => sw.ElapsedMilliseconds); } return(result); } catch (Exception e) when((translatedException = SpannerException.TryTranslateRpcException(e)) != null) { throw translatedException; } }
/// <summary> /// Returns true if the exception represents a transient error in Spanner. /// This indicates that the operation may succeed if it is attempted again. /// Common errors that can cause this include temporary network interruption /// or the service being temporarily unavailable. /// </summary> /// <returns>True if the exception represents an error that may succeed on a retry.</returns> public static bool IsTransientSpannerFault(this Exception exception) { var spannerException = exception as SpannerException ?? SpannerException.TryTranslateRpcException(exception); return(spannerException != null && spannerException.IsRetryable); }
internal static SpannerException TryTranslateRpcException(Exception possibleRpcException) { SpannerException spannerException = null; var aggregateException = possibleRpcException as AggregateException; var rpcException = possibleRpcException as RpcException; if (aggregateException?.InnerExceptions != null) { spannerException = (SpannerException)aggregateException.InnerExceptions .FirstOrDefault(x => x is SpannerException); rpcException = (RpcException)aggregateException.InnerExceptions .FirstOrDefault(x => x is RpcException); } if (rpcException != null) { spannerException = new SpannerException(rpcException); } return(spannerException); }
internal static void WithErrorTranslationAndProfiling(Action t, string name, Logger logger) { SpannerException translatedException; try { Stopwatch sw = null; if (logger.LogPerformanceTraces) { sw = Stopwatch.StartNew(); } t(); if (sw != null) { logger.LogPerformanceCounterFn($"{name}.Duration", x => sw.ElapsedMilliseconds); } } catch (Exception e) when((translatedException = SpannerException.TryTranslateRpcException(e)) != null) { throw translatedException; } }