Skip to content

Commit 9589dff

Browse files
committed
Improve error message
This related to the "cannot generate message" fallback message.
1 parent 34ae3ac commit 9589dff

4 files changed

Lines changed: 7 additions & 7 deletions

File tree

CSF.Screenplay/Reporting/PerformanceReportBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,9 @@ static string TryGetReport(ICanReport reporter, Actor actor, IFormatsReportFragm
274274
{
275275
return reporter.GetReportFragment(actor, formatter).FormattedFragment;
276276
}
277-
catch
277+
catch(Exception e)
278278
{
279-
return ReportStrings.ReportErrorMessage;
279+
return string.Format(ReportStrings.ReportErrorMessageFormat, e.GetType().FullName, e.Message);
280280
}
281281
}
282282

CSF.Screenplay/Resources/ReportStrings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ internal static class ReportStrings
2323
internal static string FallbackReportFormat => resourceManager.GetString("FallbackReportFormat");
2424

2525
/// <summary>Gets a report text which is recorded when a performable raises an exception from <see cref="ICanReport.GetReportFragment(Actor, IFormatsReportFragment)"/>.</summary>
26-
internal static string ReportErrorMessage => resourceManager.GetString("ReportErrorMessage");
26+
internal static string ReportErrorMessageFormat => resourceManager.GetString("ReportErrorMessage");
2727
}
2828
}

CSF.Screenplay/Resources/ReportStrings.restext

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ ActorGainedAbilityFormat = {0} is able to {1}
33
ActorSpotlitFormat = {0} was put into the spotlight
44
SpotlightTurnedOff = The spotlight was turned off
55
FallbackReportFormat = {0} performed {1}
6-
ReportErrorMessage = An unexpected error occurred getting the report text for this performable
6+
ReportErrorMessage = An unexpected error occurred getting the report text for this performable. {0}: {1}

Tests/CSF.Screenplay.Tests/Reporting/PerformanceReportBuilderTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,12 @@ public void RecordFailureForCurrentPerformableShouldUseAFallbackReportIfGettingT
222222
ICanReport performable,
223223
string performancePhase)
224224
{
225-
Mock.Get(performable).Setup(x => x.GetReportFragment(actor, It.IsAny<IFormatsReportFragment>())).Throws<InvalidOperationException>();
225+
Mock.Get(performable).Setup(x => x.GetReportFragment(actor, It.IsAny<IFormatsReportFragment>())).Throws(new Exception("Report Generation error"));
226226
sut.BeginPerformable(performable, actor, performancePhase);
227227
sut.RecordFailureForCurrentPerformable(new Exception("An error occurred"), performable, actor);
228228
var report = sut.GetReport(outcome);
229-
Assert.That(report.Reportables,
230-
Has.One.Matches<PerformableReport>(x => x.Report == "An unexpected error occurred getting the report text for this performable"));
229+
Assert.That(report.Reportables.Single().Report,
230+
Is.EqualTo("An unexpected error occurred getting the report text for this performable. System.Exception: Report Generation error"));
231231
}
232232

233233
[Test, AutoMoqData]

0 commit comments

Comments
 (0)