---
title: "Where to handle the error an AI reviewer says nobody catches | Proofline"
description: "Before you answer a \"this can fail\" comment, name a realistic way the call fails and the closest layer that can act on it."
url: https://proofline.sh/learn/ai-review-unhandled-error-comment/
---

[Learning center](/learn/)

# Where to handle the error an AI reviewer says nobody catches

Before you answer a "this can fail" comment, name a realistic way the call fails and the closest layer that can act on it. Change the code when that layer is the one under review and it lets the error pass; dismiss the comment when no supported path reaches the failure, or when a framework boundary above already turns it into the right outcome.

Code review The Proofline team November 22, 2026 4 min read

## Name the cause before the handler

Most "this can throw" comments are true in the narrow sense: almost any call can raise something. The question is whether a real input, state or dependency failure reaches this line. Write down the cause in one sentence, such as "the user's template renders to a list" or "the device is not registered yet", and check it against the code that feeds the call. If you cannot write that sentence, a test that forces the failure is cheaper than an argument.

Then ask who should hear about the failure, and in what form:

-   The code under review, when it can recover or translate the error into something its caller understands.
-   The caller, when only the caller knows what to do, so the error should propagate unchanged.
-   A framework boundary, such as a web server's error handler or a task runner, when the right outcome is a logged error and a generic failure response.

## A failure the caller needed as data

In October 2026, a Home Assistant pull request added a tool that lets a conversation agent call any Home Assistant action. Copilot's review on the first commit said that "unhashable template keys can abort conversations instead of returning tool errors," and opened an inline item titled "Handle template-rendering TypeError as a tool error". [Copilot review](https://github.com/home-assistant/core/pull/188641#pullrequestreview-5646768244)

The cause is concrete. The tool accepts action data from a language model, and a key in that data can be a template. A template that renders to a list cannot be a dictionary key, because Python dictionary keys must be [hashable](https://docs.python.org/3/glossary.html#term-hashable) and mutable containers such as lists are not. Evaluating `{['a']: 'b'}` in Python 3 raises `TypeError: unhashable type: 'list'`.

The right handler was the tool itself. Its caller is a model that can correct its own call if it gets an error result, and an exception that escapes the tool ends the conversation instead. The author's commit `13fd600` says so: "A template key in the data that renders to a list or dict raised a TypeError out of the tool and ended the conversation." It continues, "The tool now returns it as a tool error, so the LLM can correct the call." [Pull request](https://github.com/home-assistant/core/pull/188641) The merged code catches the error where the data is prepared:

```
try:
    params = async_prepare_call_from_config(hass, config)
# A template that renders to a list or dict cannot be a key in the data
except (HomeAssistantError, TypeError) as err:
    return ToolResult(data={"error": str(err)}, error=True)
```

The pull request's tests include a case with the data `{"{{ ['a'] }}": "b"}`, so the failure the reviewer described is now part of the suite. Copilot's next review listed the item as resolved, and the pull request merged on 27 October 2026.

## A failure that the supported path cannot reach

A day later, another Home Assistant pull request added diagnostics to the Broadlink integration. The new function looks up the device directly:

```
device = hass.data[BROADLINK_DATA].devices[entry.entry_id]
```

Copilot's summary said that "Diagnostics requests for failed-setup or unloaded entries raise KeyError and return HTTP 500," because the code has no fallback for a missing device. [Copilot review](https://github.com/home-assistant/core/pull/189124#pullrequestreview-5680406187)

The author answered with the cause analysis: "The frontend only offers the diagnostics download for config entries (and their devices) in the `loaded` state, and a Broadlink entry only reaches that state once the device is registered, so this lookup can't miss in practice." The reply added: "Keeping it consistent with how other integrations access their runtime data in diagnostics." [Author's reply](https://github.com/home-assistant/core/pull/189124#discussion_r4400772180) The pull request merged the same day, 28 October 2026, with the lookup unchanged.

The dismissal holds for the supported path. It leaves one path open. The backend view that serves diagnostics, `DownloadDiagnosticsView` in [`homeassistant/components/diagnostics/__init__.py`](https://github.com/home-assistant/core/blob/f90f27f/homeassistant/components/diagnostics/__init__.py), requires an administrator and returns 404 for an unknown entry, but it does not check the entry's state. An administrator who calls `/api/diagnostics/config_entry/<id>` directly for an entry whose device is missing from that dictionary would reach the `KeyError`. aiohttp's server logs an uncaught handler exception as "Error handling request" and answers with a 500 response, as its [`web_protocol.py`](https://github.com/aio-libs/aiohttp/blob/master/aiohttp/web_protocol.py) shows. That is the framework boundary doing its job for a request outside the supported flow: the failure is loud and logged, and nothing is corrupted. This check covered the backend view and aiohttp. It did not cover the frontend code that decides when to offer the download.

## Decide where it belongs

| What you find | Response |
| --- | --- |
| A realistic cause reaches the call, and this code can recover or translate the error for its caller | Change: handle it here, as the call action tool does |
| A realistic cause reaches the call, but only the caller knows what to do | Dismiss the request to catch it here; check that the error propagates and that the caller's docs or types say it can fail |
| The failure is possible only outside supported use, and a framework boundary logs it and fails the request | Dismiss with the reason, as in the Broadlink reply |
| The cause is real and the failure would corrupt data or leave partial state | Change, whatever the frequency |
| You cannot tell whether the cause is reachable | Add a test that forces the failure and observe what the caller gets |

Catching an error to satisfy the comment, without a caller that needs it, usually produces the opposite finding next week: an error that is now caught and ignored. The [swallowed-exception guide](/learn/ai-review-swallowed-exception-comment/) covers that case. When the claim depends on code outside the diff, as the Broadlink one did, the reviewer may not have seen it; [testing what the reviewer could see](/learn/test-reviewer-context-beyond-diff/) shows how to check.

## One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. [Eligibility and fair-use terms](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [When a caught-and-ignored error should reach the caller](/learn/ai-review-swallowed-exception-comment/)
    
    Code review The Proofline team November 22, 2026 4 min read
    
-   ### [Does your code reviewer read beyond the diff? Build a test pull request](/learn/test-reviewer-context-beyond-diff/)
    
    Code review The Proofline team November 20, 2026 4 min read
