# CompositionErrorContext

Artifact: [androidx.compose.runtime:runtime](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/tooling/CompositionErrorContext.kt+class:androidx.compose.runtime.tooling.CompositionErrorContext) Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.9.0) Common/AllAndroid/JVM
- Cmn

  ```
  sealed interface CompositionErrorContext
  ```

*** ** * ** ***

Provides a way to attach a compose stack trace to a throwable based on a location of compose node in composition. This context is expected to be used by custom node implementations to attach diagnostic compose stack traces to exceptions in passes that are not handled by the Compose runtime (example: measure / layout / draw in Compose UI).

Compose runtime automatically appends information about exceptions that happen in composition and effects.

## Summary

| ### Public functions |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-throwable/index.html.https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionErrorContext#(kotlin.Throwable).attachComposeStackTrace(kotlin.Any)(composeNode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)` Attaches a Compose stack trace to a throwable as a suppressed `https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/DiagnosticComposeException`. | Cmn |

## Public functions

### Throwable.attachComposeStackTrace

Cmn Artifact: [androidx.compose.runtime:runtime](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/tooling/CompositionErrorContext.kt+function:attachComposeStackTrace) Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.9.0)

```
fun Throwable.attachComposeStackTrace(composeNode: Any): Boolean
```

Attaches a Compose stack trace to a throwable as a suppressed `https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/DiagnosticComposeException`. Has no effect if:

- Throwable already contains a suppressed `https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/DiagnosticComposeException`

- `https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionErrorContext#(kotlin.Throwable).attachComposeStackTrace(kotlin.Any)` is not found in composition

- composition contains no source information (e.g. in minified builds)

| Parameters |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-throwable/index.html` | throwable to attach a compose stack trace to |
| `composeNode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html` | closest node to where exception was originally thrown |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if the exception was attached, false otherwise |