Skip to content

fix: unwrap exceptions thrown in event handlers#385

Merged
vbreuss merged 3 commits into
mainfrom
topic/fix-thrown-exception-from-eventhandlers
Jan 24, 2026
Merged

fix: unwrap exceptions thrown in event handlers#385
vbreuss merged 3 commits into
mainfrom
topic/fix-thrown-exception-from-eventhandlers

Conversation

@vbreuss
Copy link
Copy Markdown
Member

@vbreuss vbreuss commented Jan 24, 2026

This PR ensures that exceptions thrown from event handlers are not wrapped in TargetInvocationException when raised through mock events. The fix unwraps the inner exception during event handler invocation.

Key Changes:

  • Modified MockRegistration.Raise to catch and unwrap TargetInvocationException when invoking event handlers
  • Added test case verifying that exceptions from event subscriptions are properly thrown without wrapping

@vbreuss vbreuss self-assigned this Jan 24, 2026
@vbreuss vbreuss added the bug Something isn't working label Jan 24, 2026
Copilot AI review requested due to automatic review settings January 24, 2026 06:03
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes issue #383 by ensuring that exceptions thrown from event handlers are not wrapped in TargetInvocationException when raised through mock events. The fix unwraps the inner exception during event handler invocation.

Changes:

  • Modified MockRegistration.Raise to catch and unwrap TargetInvocationException when invoking event handlers
  • Added test case verifying that exceptions from event subscriptions are properly thrown without wrapping
  • Minor formatting improvements to method invocation calls

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
Source/Mockolate/MockRegistration.cs Added try-catch block to unwrap TargetInvocationException and preserve original exceptions from event handlers; minor formatting changes
Tests/Mockolate.Tests/MockEvents/RaiseTests.cs Added test verifying exceptions from event handlers are not wrapped

Comment thread Source/Mockolate/MockRegistration.cs Outdated
Copilot AI review requested due to automatic review settings January 24, 2026 06:08
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 24, 2026

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.3 LTS (Noble Numbat)
Intel Xeon Platinum 8370C CPU 2.80GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.102
[Host] : .NET 10.0.2 (10.0.2, 10.0.225.61305), X64 RyuJIT x86-64-v4

Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15
LaunchCount=1 WarmupCount=10

Method Mean Error StdDev Gen0 Gen1 Allocated
Simple_Mockolate 1.611 μs 0.0116 μs 0.0103 μs 0.1507 - 3.73 KB
Simple_Moq 136.123 μs 1.0638 μs 0.9950 μs 0.4883 0.2441 14.56 KB
Simple_NSubstitute 6.142 μs 0.0152 μs 0.0142 μs 0.3662 - 9.09 KB
Simple_FakeItEasy 6.256 μs 0.0230 μs 0.0216 μs 0.3281 - 8.12 KB

@vbreuss vbreuss enabled auto-merge (squash) January 24, 2026 06:09
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread Source/Mockolate/MockRegistration.cs
@vbreuss vbreuss changed the title fix: thrown exception from event handlers fix: unwrap exceptions thrown from event handlers Jan 24, 2026
@vbreuss vbreuss changed the title fix: unwrap exceptions thrown from event handlers fix: unwrap exceptions thrown in event handlers Jan 24, 2026
@sonarqubecloud
Copy link
Copy Markdown

@github-actions
Copy link
Copy Markdown

Test Results

    14 files  ±0      14 suites  ±0   6m 4s ⏱️ -8s
 2 302 tests +1   2 301 ✅ +1  1 💤 ±0  0 ❌ ±0 
15 419 runs  +7  15 418 ✅ +7  1 💤 ±0  0 ❌ ±0 

Results for commit 5afc642. ± Comparison against base commit 1f5a930.

@vbreuss vbreuss merged commit 794125a into main Jan 24, 2026
12 checks passed
@vbreuss vbreuss deleted the topic/fix-thrown-exception-from-eventhandlers branch January 24, 2026 06:13
@github-actions
Copy link
Copy Markdown

This is addressed in release v1.0.1.

@github-actions github-actions Bot added the state: released The issue is released label Jan 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working state: released The issue is released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Thrown exceptions in callback handlers get wrapped

2 participants