8000 Add an exception-mapping behavior by kzu · Pull Request #285 · devlooped/stunts · GitHub
[go: up one dir, main page]

Skip to content

Add an exception-mapping behavior - #285

Merged
kzu merged 3 commits into
mainfrom
exception-mapping-behavior
Oct 8, 2026
Merged

kzu merged 3 commits into
mainfrom
exception-mapping-behavior

Conversation

@kzu
@kzu kzu commented Oct 8, 2026
Copy link
Copy Markdown
Member

Summary

  • Add ExceptionMappingBehavior so a stunt can translate an exception from the target, including a faulted Task or ValueTask, while keeping the original as InnerException when the replacement wraps it.
  • A null map result leaves the failure in place. swallow: true is the opt-in that turns that null result into the member's default value.
  • Behaviors added before this one stay outside the translated call, so exceptions they throw are left alone.

Closes #269

Test plan

  • An IOException from the target becomes the mapped exception, with the original as its inner exception
  • Awaiting a faulted Task<T> and ValueTask<T> throws the mapped exception, and IMethodReturn.Exception stays null
  • With swallowing left off, a null map result still throws and does not return a value
  • Swallowing on returns the default for sync members and faulted awaitables, while a non-null map result still fails
  • An exception thrown by a behavior added before this one is not passed to the map

Callers can translate a target failure, including a faulted task, without turning it into a successful value unless they opt in.
@kzu kzu added the enhancement New feature or request label Oct 8, 2026
@kzu
kzu enabled auto-merge (squash) October 8, 2026 01:54
@kzu
kzu disabled auto-merge October 8, 2026 01:59
Activator.CreateInstance is not available under Native AOT. Swallowed calls now return the same defaults the stunt already registers.
@kzu
kzu enabled auto-merge (squash) October 8, 2026 02:03
Callers who already registered custom defaults can pass that provider instead of getting a fresh one.
@kzu
kzu merged commit 82fd2a4 into main Oct 8, 2026
@kzu
kzu deleted the exception-mapping-behavior branch October 8, 2026 02:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an exception-mapping behavior

1 participant

0