Skip to content

Commit fa1568f

Browse files
committed
Fixed #98 Line breaks in Exception.Message is removed when submitting the exception
1 parent 45d9e2f commit fa1568f

File tree

3 files changed

+47
-24
lines changed

3 files changed

+47
-24
lines changed

src/Exceptionless.Tests/Plugins/PluginTests.cs

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,52 @@ public void HandleAggregateExceptionsPlugin_SingleInnerException() {
289289
plugin.Run(context);
290290
Assert.True(context.Cancel);
291291
}
292-
292+
293+
[Fact]
294+
public void HandleAggregateExceptionsPlugin_MultipleInnerException() {
295+
var submissionClient = new InMemorySubmissionClient();
296+
var client = new ExceptionlessClient("LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw");
297+
client.Configuration.Resolver.Register<ISubmissionClient>(submissionClient);
298+
299+
var plugin = new HandleAggregateExceptionsPlugin();
300+
var exceptionOne = new Exception("one");
301+
var exceptionTwo = new Exception("two");
302+
303+
var context = new EventPluginContext(client, new Event());
304+
context.ContextData.SetException(new AggregateException(exceptionOne, exceptionTwo));
305+
plugin.Run(context);
306+
Assert.True(context.Cancel);
307+
308+
client.ProcessQueue();
309+
Assert.Equal(2, submissionClient.Events.Count);
310+
}
311+
312+
[Fact]
313+
public void ErrorPlugin_WillPreserveLineBreaks() {
314+
const string message = "Test\r\nLine\r\n\tBreaks";
315+
316+
var errorPlugins = new List<IEventPlugin> {
317+
new ErrorPlugin(),
318+
new SimpleErrorPlugin()
319+
};
320+
321+
var client = CreateClient();
322+
foreach (var plugin in errorPlugins) {
323+
var context = new EventPluginContext(client, new Event());
324+
context.ContextData.SetException(new NotSupportedException(message));
325+
plugin.Run(context);
326+
Assert.False(context.Cancel);
327+
328+
var error = context.Event.GetError();
329+
if (error != null)
330+
Assert.Equal(message, error.Message);
331+
else
332+
Assert.Equal(message, context.Event.GetSimpleError().Message);
333+
}
334+
}
335+
293336
[Fact (Skip = "There is a bug in the .NET Framework where non thrown exceptions with non custom stack traces cannot be computed #116")]
294-
public void CanHandleExceptionWithOverriddenStackTrace() {
337+
public void ErrorPlugin_CanHandleExceptionWithOverriddenStackTrace() {
295338
var client = CreateClient();
296339
var plugin = new ErrorPlugin();
297340

@@ -311,25 +354,6 @@ public void CanHandleExceptionWithOverriddenStackTrace() {
311354
Assert.True(error.StackTrace.Count > 0);
312355
}
313356

314-
[Fact]
315-
public void HandleAggregateExceptionsPlugin_MultipleInnerException() {
316-
var submissionClient = new InMemorySubmissionClient();
317-
var client = new ExceptionlessClient("LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw");
318-
client.Configuration.Resolver.Register<ISubmissionClient>(submissionClient);
319-
320-
var plugin = new HandleAggregateExceptionsPlugin();
321-
var exceptionOne = new Exception("one");
322-
var exceptionTwo = new Exception("two");
323-
324-
var context = new EventPluginContext(client, new Event());
325-
context.ContextData.SetException(new AggregateException(exceptionOne, exceptionTwo));
326-
plugin.Run(context);
327-
Assert.True(context.Cancel);
328-
329-
client.ProcessQueue();
330-
Assert.Equal(2, submissionClient.Events.Count);
331-
}
332-
333357
[Fact]
334358
public void ErrorPlugin_DiscardDuplicates() {
335359
var errorPlugins = new List<IEventPlugin> {

src/Exceptionless/Extensions/ToErrorModelExtensions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ private static bool ValueIsEmpty(object value) {
135135

136136
private static string GetMessage(this Exception exception) {
137137
string defaultMessage = String.Format("Exception of type '{0}' was thrown.", exception.GetType().FullName);
138-
string message = !String.IsNullOrEmpty(exception.Message) ? String.Join(" ", exception.Message.Split(new[] { ' ', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)).Trim() : null;
139-
138+
string message = !String.IsNullOrEmpty(exception.Message) ? exception.Message.Trim() : null;
140139
return !String.IsNullOrEmpty(message) ? message : defaultMessage;
141140
}
142141

src/Exceptionless/Extensions/ToSimpleErrorModelExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private static bool ValueIsEmpty(object value) {
9393

9494
private static string GetMessage(Exception exception) {
9595
string defaultMessage = String.Format("Exception of type '{0}' was thrown.", exception.GetType().FullName);
96-
string message = !String.IsNullOrEmpty(exception.Message) ? String.Join(" ", exception.Message.Split(new[] { ' ', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)).Trim() : null;
96+
string message = !String.IsNullOrEmpty(exception.Message) ? exception.Message.Trim() : null;
9797

9898
return !String.IsNullOrEmpty(message) ? message : defaultMessage;
9999
}

0 commit comments

Comments
 (0)