use-error-info · git:20260427.cc366ee · 2026-04-27 · sha256 613ae9b86df62d97

use-error-info git:20260427.cc366eeA

Immutable. This exact content never changes and is served at /api/v1/blob/613ae9b86df62d97.

---
name: use-error-info
description: When handling errors locally instead of propagating them, include the error data in logs or messages. Never discard caught errors with `_`. Use when writing try/catch, Result handling, or error case branches.
user-invocable: false
---

# エラー処理時にエラーデータを使う

エラーのようなものをcatchやcaseで受け取って、
そのまま上流にエラーを伝播させるのではなく、
その場所でエラーを処理するときは、
エラーデータを適切に使ってください。

例えば出現する原因を修正するのは困難だけど、
エラーによって致命的な問題にならない場合は、
普通は警告ログなどを出力してそのまま続行します。
その時警告ログにはエラーデータの内容を含めて、
開発者や利用者が問題を把握しやすいようにしてください。

エラーデータを`_`とかに代入してそのまま捨ててしまうことは禁止です。