Skip to content

Add an exception-mapping behavior #269

Description

@kzu

Summary

Ship a behavior that translates or wraps an exception from the target. Swallowing a failure is a separate, off-by-default option.

API

The map is Func<Exception, Exception?>. Null means leave the exception as it is. Any other instance replaces it. A separate switch, default off, lets the map turn a failure into a successful value.

Behavior

  • Observe both failure channels through Proceed: a synchronous throw, and a faulted Task or ValueTask.
  • A wrapped exception keeps the original as InnerException.
  • A translated synchronous exception is still thrown by the stunt. A translated task fault remains a fault of the returned awaitable, with IMethodReturn.Exception null.
  • Exceptions thrown by behaviors outside this one are left alone.

Acceptance

  • An IOException from the target becomes the mapped exception, and the original is its inner exception.
  • Awaiting a faulted Task<T> throws the mapped exception.
  • With swallowing left off, the map cannot turn a failure into a value.

Back this issue
Back this issue

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions