Package com.tnsai.exceptions
Class ThrowableContextDecorator
java.lang.Object
com.tnsai.exceptions.ThrowableContextDecorator
Helper for the catch-side of framework boundaries.
When framework code catches a third-party throwable that doesn't
extend TnsAIException, calling enrich(Throwable)
attaches the current AgentContext via a ContextualWrapper
so downstream logging / ErrorEmitter sees the correlation
fields. TnsAIException instances pass through unchanged because
they already capture context at construction.
Typical usage:
try {
httpClient.execute(request);
} catch (IOException e) {
// ContextualWrapper attaches current agent / role / session / tenant.
throw ThrowableContextDecorator.enrich(e);
}
enrich returns a RuntimeException so the caller can
throw the result directly without changing the surrounding
method signature.
- Since:
- 0.5.0 (issue #90)
-
Method Summary
Modifier and TypeMethodDescriptionstatic RuntimeExceptionAttach the currentAgentContexttotif it isn't already context-aware.
-
Method Details
-
enrich
Attach the currentAgentContexttotif it isn't already context-aware. Returns the original throwable unchanged when:tis aTnsAIException— already context-capturedtis aContextualWrapper— already wrapped- no
AgentContextis currently active — nothing to attach
ContextualWrappercarrying the current context.- Parameters:
t- throwable to enrich; must not be null- Returns:
- a
RuntimeExceptionsuitable for re-throwing — either the original (when it can't be improved) or aContextualWrapper
-