@@ -290,47 +290,59 @@ private async Task InnerProcessCacheAsync(string file, CancellationToken cancell
290290
291291 _options . LogDebug ( "Reading cached envelope: {0}" , file ) ;
292292
293- var stream = _fileSystem . OpenFileForReading ( file ) ;
293+ try
294+ {
295+ var stream = _fileSystem . OpenFileForReading ( file ) ;
294296#if NETFRAMEWORK || NETSTANDARD2_0
295- using ( stream )
297+ using ( stream )
296298#else
297- await using ( stream . ConfigureAwait ( false ) )
299+ await using ( stream . ConfigureAwait ( false ) )
298300#endif
299- using ( var envelope = await Envelope . DeserializeAsync ( stream , cancellation ) . ConfigureAwait ( false ) )
300- {
301- // Don't even try to send it if we are requesting cancellation.
302- cancellation . ThrowIfCancellationRequested ( ) ;
303-
304- try
305301 {
306- _options . LogDebug ( "Sending cached envelope: {0}" , envelope . TryGetEventId ( _options . DiagnosticLogger ) ) ;
302+ using ( var envelope = await Envelope . DeserializeAsync ( stream , cancellation ) . ConfigureAwait ( false ) )
303+ {
304+ // Don't even try to send it if we are requesting cancellation.
305+ cancellation . ThrowIfCancellationRequested ( ) ;
307306
308- await _innerTransport . SendEnvelopeAsync ( envelope , cancellation ) . ConfigureAwait ( false ) ;
309- }
310- // OperationCancel should not log an error
311- catch ( OperationCanceledException ex )
312- {
313- _options . LogDebug ( "Canceled sending cached envelope: {0}, retrying after a delay." , ex , file ) ;
314- // Let the worker catch, log, wait a bit and retry.
315- throw ;
316- }
317- catch ( Exception ex ) when ( ex is HttpRequestException or WebException or SocketException or IOException )
318- {
319- _options . LogError ( "Failed to send cached envelope: {0}, retrying after a delay." , ex , file ) ;
320- // Let the worker catch, log, wait a bit and retry.
321- throw ;
322- }
323- catch ( Exception ex ) when ( ex . Source == "FakeFailingTransport" )
324- {
325- // HACK: Deliberately sent from unit tests to avoid deleting the file from processing
326- return ;
327- }
328- catch ( Exception ex )
329- {
330- _options . ClientReportRecorder . RecordDiscardedEvents ( DiscardReason . CacheOverflow , envelope ) ;
331- LogFailureWithDiscard ( file , ex ) ;
307+ try
308+ {
309+ _options . LogDebug ( "Sending cached envelope: {0}" ,
310+ envelope . TryGetEventId ( _options . DiagnosticLogger ) ) ;
311+
312+ await _innerTransport . SendEnvelopeAsync ( envelope , cancellation ) . ConfigureAwait ( false ) ;
313+ }
314+ // OperationCancel should not log an error
315+ catch ( OperationCanceledException ex )
316+ {
317+ _options . LogDebug ( "Canceled sending cached envelope: {0}, retrying after a delay." , ex , file ) ;
318+ // Let the worker catch, log, wait a bit and retry.
319+ throw ;
320+ }
321+ catch ( Exception ex ) when ( ex is HttpRequestException or WebException or SocketException
322+ or IOException )
323+ {
324+ _options . LogError ( "Failed to send cached envelope: {0}, retrying after a delay." , ex , file ) ;
325+ // Let the worker catch, log, wait a bit and retry.
326+ throw ;
327+ }
328+ catch ( Exception ex ) when ( ex . Source == "FakeFailingTransport" )
329+ {
330+ // HACK: Deliberately sent from unit tests to avoid deleting the file from processing
331+ return ;
332+ }
333+ catch ( Exception ex )
334+ {
335+ _options . ClientReportRecorder . RecordDiscardedEvents ( DiscardReason . CacheOverflow , envelope ) ;
336+ LogFailureWithDiscard ( file , ex ) ;
337+ }
338+ }
332339 }
333340 }
341+ catch ( JsonException ex )
342+ {
343+ // Log deserialization errors
344+ LogFailureWithDiscard ( file , ex ) ;
345+ }
334346
335347 // Envelope & file stream must be disposed prior to reaching this point
336348
0 commit comments