Skip to content

Commit 800b860

Browse files
committed
Support nested C# exceptions
* Inner exceptions * Aggregate exceptions (from wait operations on failed tasks) * Exceptions thrown from asynchronous code
1 parent 69d95d2 commit 800b860

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

lib/fluent/plugin/exception_detector.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,23 @@ def self.supported
5959
:java_start_exception),
6060
rule(:java_after_exception, /^[\r\n]*$/, :java_after_exception),
6161
rule([:java_after_exception, :java], /^[\t ]+(?:eval )?at /, :java),
62+
63+
# C# nested exception
64+
rule([:java_after_exception, :java],
65+
/^[\t ]+--- End of inner exception stack trace ---/,
66+
:java),
67+
68+
# C# aggregate exception
69+
rule([:java_after_exception, :java],
70+
/^---> \(Inner Exception #[0-9]+\)/,
71+
:java),
72+
73+
# C# exception from async code
74+
rule([:java_after_exception, :java],
75+
%r{^---\sEnd\sof\sstack\strace\sfrom\sprevious\s
76+
location\swhere\sexception\swas\sthrown\s---}x,
77+
:java),
78+
6279
rule([:java_after_exception, :java], /^[\t ]*(?:Caused by|Suppressed):/,
6380
:java_after_exception),
6481
rule([:java_after_exception, :java],

test/plugin/test_exception_detector.rb

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,50 @@ class ExceptionDetectorTest < Test::Unit::TestCase
256256
at System.Threading.Thread.StartInternal () [0x00000] in <filename unknown>:0
257257
END
258258

259+
CSHARP_NESTED_EXC = <<END.freeze
260+
System.InvalidOperationException: This is the outer exception ---> System.InvalidOperationException: This is the inner exception
261+
at ExampleApp.NestedExceptionExample.LowestLevelMethod() in c:/ExampleApp/ExampleApp/NestedExceptionExample.cs:line 33
262+
at ExampleApp.NestedExceptionExample.ThirdLevelMethod() in c:/ExampleApp/ExampleApp/NestedExceptionExample.cs:line 28
263+
at ExampleApp.NestedExceptionExample.SecondLevelMethod() in c:/ExampleApp/ExampleApp/NestedExceptionExample.cs:line 18
264+
--- End of inner exception stack trace ---
265+
at ExampleApp.NestedExceptionExample.SecondLevelMethod() in c:/ExampleApp/ExampleApp/NestedExceptionExample.cs:line 22
266+
at ExampleApp.NestedExceptionExample.TopLevelMethod() in c:/ExampleApp/ExampleApp/NestedExceptionExample.cs:line 11
267+
at ExampleApp.Program.Main(String[] args) in c:/ExampleApp/ExampleApp/Program.cs:line 11
268+
END
269+
270+
CSHARP_AGGREGATE_EXC = <<END.freeze
271+
System.AggregateException: One or more errors occurred. (This is an exception) ---> System.InvalidOperationException: This is an exception
272+
at ExampleApp.AsyncExceptionExample.LowestLevelMethod() in c:/ExampleApp/ExampleApp/AsyncExceptionExample.cs:line 28
273+
at ExampleApp.AsyncExceptionExample.ThirdLevelMethod() in c:/ExampleApp/ExampleApp/AsyncExceptionExample.cs:line 23
274+
at ExampleApp.AsyncExceptionExample.SecondLevelMethod() in c:/ExampleApp/ExampleApp/AsyncExceptionExample.cs:line 17
275+
at ExampleApp.AsyncExceptionExample.TopLevelMethod() in c:/ExampleApp/ExampleApp/AsyncExceptionExample.cs:line 12
276+
--- End of inner exception stack trace ---
277+
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
278+
at System.Threading.Tasks.Task.Wait()
279+
at ExampleApp.Program.Main(String[] args) in c:/ExampleApp/ExampleApp/Program.cs:line 12
280+
---> (Inner Exception #0) System.InvalidOperationException: This is an exception
281+
at ExampleApp.AsyncExceptionExample.LowestLevelMethod() in c:/ExampleApp/ExampleApp/AsyncExceptionExample.cs:line 28
282+
at ExampleApp.AsyncExceptionExample.ThirdLevelMethod() in c:/ExampleApp/ExampleApp/AsyncExceptionExample.cs:line 23
283+
at ExampleApp.AsyncExceptionExample.SecondLevelMethod() in c:/ExampleApp/ExampleApp/AsyncExceptionExample.cs:line 17
284+
at ExampleApp.AsyncExceptionExample.TopLevelMethod() in c:/ExampleApp/ExampleApp/AsyncExceptionExample.cs:line 12<---
285+
END
286+
287+
CSHARP_ASYNC_EXC = <<END.freeze
288+
System.InvalidOperationException: This is an exception
289+
at ExampleApp2.AsyncExceptionExample.LowestLevelMethod() in c:/ExampleApp/ExampleApp/AsyncExceptionExample.cs:line 36
290+
at ExampleApp2.AsyncExceptionExample.<ThirdLevelMethod>d__2.MoveNext() in c:/ExampleApp/ExampleApp/AsyncExceptionExample.cs:line 31
291+
--- End of stack trace from previous location where exception was thrown ---
292+
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
293+
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
294+
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
295+
at ExampleApp2.AsyncExceptionExample.<SecondLevelMethod>d__1.MoveNext() in c:/ExampleApp/ExampleApp/AsyncExceptionExample.cs:line 25
296+
--- End of stack trace from previous location where exception was thrown ---
297+
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
298+
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
299+
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
300+
at ExampleApp2.AsyncExceptionExample.<TopLevelMethod>d__0.MoveNext() in c:/ExampleApp/ExampleApp/AsyncExceptionExample.cs:line 14
301+
END
302+
259303
RUBY_EXC = <<END.freeze
260304
NoMethodError (undefined method `resursivewordload' for #<BooksController:0x007f8dd9a0c738>):
261305
app/controllers/books_controller.rb:69:in `recursivewordload'
@@ -570,6 +614,9 @@ def test_js
570614

571615
def test_csharp
572616
check_exception(CSHARP_EXC, false)
617+
check_exception(CSHARP_NESTED_EXC, false)
618+
check_exception(CSHARP_AGGREGATE_EXC, false)
619+
check_exception(CSHARP_ASYNC_EXC, false)
573620
end
574621

575622
def test_python
@@ -627,6 +674,9 @@ def test_mixed_languages
627674
check_exception(GO_ON_GAE_EXC, false)
628675
check_exception(GO_SIGNAL_EXC, false)
629676
check_exception(CSHARP_EXC, false)
677+
check_exception(CSHARP_NESTED_EXC, false)
678+
check_exception(CSHARP_AGGREGATE_EXC, false)
679+
check_exception(CSHARP_ASYNC_EXC, false)
630680
check_exception(V8_JS_EXC, false)
631681
check_exception(RUBY_EXC, false)
632682
check_exception(DART_ERR, false)

0 commit comments

Comments
 (0)