# Debug with Niro

**When something fails, you want facts about the code around the failure:** where an error comes from and who catches it, who writes a wrong value, which service answers a failing call, what a change reached, which setting a call depends on, and what a slow method does. Niro answers each of these from the code. The graph answers are the same every time on the same graph; a text search (`code_grep`) can stop early on a busy machine, and then says PARTIAL and how to carry on. An exception is an error a method throws, which a caller further up may catch.

## Pick the playbook by symptom

| What you see | First tools (with the short `answer` form) | Playbook |
| --- | --- | --- |
| An error message or a stack trace | `code_grep` for the message (`answer=locations`), `get_source_code`, `get_exception_flow` both ways | [Playbook: debug an error message or a stack trace](https://help.niroai.dev/cli/playbook-debug-exception/) |
| A wrong value in a table or a response | `get_data_resource_usage`, `code_grep` for the setter (`answer=names`), `get_impact_analysis` (`answer=names`) | [Playbook: debug a wrong value](https://help.niroai.dev/cli/playbook-debug-wrong-value/) |
| A call to another service fails | `find_outbound_http_calls`, `find_handler`, `get_service_topology`, `niro route-rule unconnected` | [Playbook: debug a failing call between services](https://help.niroai.dev/cli/playbook-debug-failing-service-call/) |
| It broke after a change | `get_blast_radius` with `method_fqns` (`answer=count`, then `names`) | [Playbook: "it broke after my change"](https://help.niroai.dev/cli/playbook-debug-after-a-change/) |
| It works here and not there | `niro env list`, `code_grep` over config files, `niro route-rule unconnected` | [Playbook: debug config and environment](https://help.niroai.dev/cli/playbook-debug-config/) |
| A path is slow | `get_call_chain direction=callees` (`answer=count`, then full), `get_data_resource_usage` | [Playbook: debug a slow path](https://help.niroai.dev/cli/playbook-debug-slow-path/) |
| A message was sent and nothing happened | `get_event_producers_and_handlers`, `find_orphaned_events` | [Playbook: data stores and events](https://help.niroai.dev/cli/playbook-data-and-events/) |

Every playbook shows the real answers, says why they are complete or where they are not, and compares them with grep and file reads.

## How

```
niro ask get_exception_flow method_fqn=PaymentService.charge
niro ask get_exception_flow method_fqn=PaymentService.charge direction=upstream exception_type=TimeoutException

```

- **Downstream** (the default) lists the exceptions that can leave the method, and where each is thrown and caught, 3 levels deep by default and 5 at most.

- **Upstream** lists which callers must handle a given exception. It needs `exception_type`. Without it, the answer is "Error: direction=upstream needs 'exception_type'".

Two other tools help while debugging:

- `get_call_chain` with `purpose=DEBUG` adds the source code of the method you ask about.

- `find_handler` tells you which code answers a call to another service.

## Known limits

- An exception that is caught and wrapped in another can still be listed as escaping.

- A catch is matched only by the exact exception name.

## Root cause analysis

**Root cause analysis from your alerts (for example from Sentry, Slack or Jira) is a hosted Niro feature.** The local graph does not answer it. See [Features of hosted Niro](https://help.niroai.dev/cli/hosted-only/).