# Hands-on Rust: How do I debug a call chain in Rust?

**URL:** <https://forum.devtalk.com/t/hands-on-rust-how-do-i-debug-a-call-chain-in-rust/64115>\
**Category:** PragProg Customers\
**Tags:** question, book-hands-on-rust\
**Created:** [14 July 2022 10:57 UTC](https://forum.devtalk.com/t/hands-on-rust-how-do-i-debug-a-call-chain-in-rust/64115 "2022-07-14T10:57:35Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![herbert](https://forum.devtalk.com/user_avatar/forum.devtalk.com/herbert/32/1233_2.png) [@herbert](https://forum.devtalk.com/u/herbert)\
**Post date:** [14 July 2022 12:23 UTC](https://forum.devtalk.com/t/hands-on-rust-how-do-i-debug-a-call-chain-in-rust/64115/3 "2022-07-14T12:23:33Z")

</div>

Hi,

Thanks for reading the book!

Unfortunately, Legion (the ECS) is responsible for the `World` access (which is what the `read_component` is handling) - and doesn’t flag that one at compile time. I really wish it did!

The issue can be caught by changing the `if let`. `if let` is like a single-case `match`, so it’s only running the enclosed code if `get_component_mut` succeeds - and continues on its way if it fails.

`get_component_mut` returns a `Result` type. So you have a few options for handling this:

The simplest way, not very specific:

```rust
if let Ok(mut health) = ecs.entry_mut(*victim).unwrap().get_component_mut::<Health>() {
} else {
     // Print an error here
}

```

Using `match`:

```rust
match ecs.entry_mut(*victim).unwrap().get_component_mut::<Health>() {
    Ok(mut health) => { // do the health deduction }
    Err(msg) => { // Handle the error, msg will tell you what went wrong }
}

```

Or you can choose to crash when things go wrong (surprisingly helpful for debugging):

```rust
let mut victim = ecs.entry_mut(*victim).unwrap().get_component_mut::<Health>().unwrap();
// Health deduction code

```

Hope that helps!

---

_[View the full topic](https://forum.devtalk.com/t/hands-on-rust-how-do-i-debug-a-call-chain-in-rust/64115)._
