dep-t-advice-0.6.2.0: Giving good advice to functions in records-of-functions.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Dep.ReaderAdvice.Basic

Description

This module contains basic examples advices.

BEWARE! These are provided for illustrative purposes only, they strive for simplicity and not robustness or efficiency.

Synopsis

Basic advices

returnMempty :: forall ca env m r. (Monad m, Monoid r) => Advice ca env m r Source #

Makes functions discard their result and always return mempty.

printArgs :: forall env m r. MonadIO m => Handle -> String -> Advice Show env m r Source #

Given a Handle and a prefix string, makes functions print their arguments to the Handle.

Synthetic call stacks

type StackFrame = NonEmpty (TypeRep, MethodName) Source #

The typeable representation of the record which contains the invoked function, along with the field name of the invoked function.

class HasSyntheticCallStack e where Source #

Class of environments that carry a SyntheticCallStack value that can be modified.

Methods

callStack :: forall f. Functor f => (SyntheticCallStack -> f SyntheticCallStack) -> e -> f e Source #

A lens from the environment to the call stack.

Instances

Instances details
HasSyntheticCallStack SyntheticCallStack Source #

The trivial case, useful when SyntheticCallStack is the environment type of a ReaderT.

Instance details

Defined in Dep.SimpleAdvice.Basic

HasSyntheticCallStack s => HasSyntheticCallStack (Const s x) Source # 
Instance details

Defined in Dep.SimpleAdvice.Basic

Methods

callStack :: Functor f => (SyntheticCallStack -> f SyntheticCallStack) -> Const s x -> f (Const s x) Source #

HasSyntheticCallStack s => HasSyntheticCallStack (Constant s x) Source # 
Instance details

Defined in Dep.SimpleAdvice.Basic

keepCallStack Source #

Arguments

:: (MonadUnliftIO m, HasSyntheticCallStack env, Exception e) 
=> (SomeException -> Maybe e)

A selector for the kinds of exceptions we want to catch. For example fromException @IOError.

-> NonEmpty (TypeRep, MethodName)

The path to the current component/method in the environment. It will be usually obtained through adviseRecord.

-> Advice ca env m r 

If the environment carries a SyntheticCallStack, make advised functions add themselves to the SyntheticCallStack before they start executing.

Caught exceptions are rethrown wrapped in SyntheticStackTraceExceptions, with the current SyntheticCallStack added.