Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/Sentry/GlobalSessionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ private void DeletePersistedSession()
}

var filePath = Path.Combine(_persistenceDirectoryPath, PersistedSessionFileName);
if (!_options.FileSystem.FileExists(filePath))
{
_options.LogDebug("A persisted session file was not found at '{0}'.", filePath);
return null;
}

try
{
var recoveredUpdate = _persistedSessionProvider(filePath);
Expand Down Expand Up @@ -195,12 +201,6 @@ private void DeletePersistedSession()

return sessionUpdate;
}
catch (Exception ex) when (ex is FileNotFoundException or DirectoryNotFoundException)
{
// Not a notable error
_options.LogDebug("A persisted session does not exist ({0}) at {1}.", ex.GetType().Name, filePath);
return null;
}
catch (Exception ex)
{
_options.LogError(ex, "Failed to recover persisted session from the file system '{0}'.", filePath);
Expand Down
36 changes: 12 additions & 24 deletions test/Sentry.Tests/GlobalSessionManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,45 +261,28 @@ public void TryRecoverPersistedSession_SessionNotStarted_ReturnsNull()
}

[Fact]
public void TryRecoverPersistedSession_FileNotFoundException_LogDebug()
public void TryRecoverPersistedSession_NoSessionFile_LogDebug()
{
// Arrange
_fixture.PersistedSessionProvider = _ => throw new FileNotFoundException();
var sut = _fixture.GetSut();
sut = new GlobalSessionManager(
_fixture.Options,
persistedSessionProvider: _ => throw new FileNotFoundException());

// Act
sut.TryRecoverPersistedSession();

// Assert
_fixture.Logger.Entries.Should().Contain(e => e.Level == SentryLevel.Debug);
}

[Fact]
public void TryRecoverPersistedSession_DirectoryNotFoundException_LogDebug()
{
// Arrange
var sut = _fixture.GetSut();
sut = new GlobalSessionManager(
_fixture.Options,
persistedSessionProvider: _ => throw new DirectoryNotFoundException());

// Act
sut.TryRecoverPersistedSession();

// Assert
_fixture.Logger.Entries.Should().Contain(e => e.Level == SentryLevel.Debug);
_fixture.Logger.Entries.Should().Contain(e =>
e.Level == SentryLevel.Debug
&& e.Message.Contains("A persisted session file was not found"));
}

[Fact]
public void TryRecoverPersistedSession_EndOfStreamException_LogError()
{
// Arrange
_fixture.PersistedSessionProvider = _ => throw new EndOfStreamException();
var sut = _fixture.GetSut();
sut = new GlobalSessionManager(
_fixture.Options,
persistedSessionProvider: _ => throw new EndOfStreamException());
sut.StartSession();

// Act
sut.TryRecoverPersistedSession();
Expand Down Expand Up @@ -391,6 +374,7 @@ public void TryRecoverPersistedSession_CrashDelegateReturnsTrueWithPauseTimestam
pausedTimestamp);

var sut = _fixture.GetSut();
sut.StartSession();

// Act
var persistedSessionUpdate = sut.TryRecoverPersistedSession();
Expand All @@ -412,6 +396,7 @@ public void TryRecoverPersistedSession_CrashDelegateIsNullWithPauseTimestamp_End
pausedTimestamp);

var sut = _fixture.GetSut();
sut.StartSession();

// Act
var persistedSessionUpdate = sut.TryRecoverPersistedSession();
Expand Down Expand Up @@ -568,6 +553,7 @@ public void TryRecoverPersistedSession_WithPendingUnhandledAndNoCrash_EndsAsUnha
pendingUnhandled: true);

var sut = _fixture.GetSut();
sut.StartSession();

// Act
var persistedSessionUpdate = sut.TryRecoverPersistedSession();
Expand All @@ -588,6 +574,7 @@ public void TryRecoverPersistedSession_WithPendingUnhandledAndCrash_EscalatesToC
pendingUnhandled: true);

var sut = _fixture.GetSut();
sut.StartSession();

// Act
var persistedSessionUpdate = sut.TryRecoverPersistedSession();
Expand All @@ -609,6 +596,7 @@ public void TryRecoverPersistedSession_WithPendingUnhandledAndPauseTimestamp_Esc
pendingUnhandled: true);

var sut = _fixture.GetSut();
sut.StartSession();

// Act
var persistedSessionUpdate = sut.TryRecoverPersistedSession();
Expand Down
Loading