Skip to content
Back to skills

Use Error Info

ASecurity

When handling errors locally instead of propagating them, include the error data in logs or messages. Never discard caught errors with `_`, and never silence a failing shell command with only `|| true`; record the failure and its exit status before continuing. Use when writing try/catch, Result handling, error case branches, or shell commands that continue after a failure.

  • 3 stars
  • 0 votes
  • 0 copies
  • 6 views
  • Added May 27, 2026
data-aishellbash

Security analysis

A100/100

Scanned December 2, 2026

npx -y skills add ncaq/konoka --skill use-error-info --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Use Error Info?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Use Error Info
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ncaq-use-error-info/badge)](https://www.skillsdirectory.com/skills/ncaq-use-error-info)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
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 `_`, and never silence a failing shell command with only `|| true`; record the failure and its exit status before continuing. Use when writing try/catch, Result handling, error case branches, or shell commands that continue after a failure.
user-invocable: false
---

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

`catch`や`case`で受け取ったエラーを、上流に伝播させずにその場で処理するときは、
受け取ったエラーデータを捨てずに、ログやメッセージに含めるなどして使ってください。
開発者や利用者が問題を把握しやすくするためです。

例えば、原因を修正するのは難しいけれど致命的な問題にはならないエラーは、
警告ログを出力してそのまま続行するのが普通です。
その警告ログにエラーデータの内容を含めます。

エラーデータを`_`などに束縛して、使わずに捨てることは禁止です。

## シェルで失敗を黙って握り潰さない

シェルで失敗しても続行したいコマンドに、
`|| true`や`|| :`だけを付けて失敗を黙って捨てることも禁止です。
受け取る変数が無いだけで、エラーデータを`_`に束縛して捨てるのと同じだからです。
黙って続行すると、後で障害を調べるときに、失敗があったこと自体が分からなくなります。
`2>/dev/null || true`のように、コマンド自身のエラーメッセージまで捨てる書き方も同じです。

何をしようとして失敗したのかと終了コードを、標準エラー出力に残してから続行してください。
systemdのサービスから実行されるスクリプトなら、標準エラー出力はjournalに記録されます。

```bash
# 避ける
systemctl --user stop foo.service || true

# 使う
systemctl --user stop foo.service || echo "foo.serviceの停止に失敗しました (exit=$?)" >&2
```

`||`の右側で展開する`$?`は、左側のコマンドの終了コードになります。

### 失敗ではない終了コード

`grep`で一致する行が無いときの終了コード1のように、
0以外の終了コードが失敗ではなく正常な結果の一つである場合は、ログに残す必要はありません。
その場合も`|| true`で全ての失敗をまとめて捨てずに、想定している終了コードだけを許してください。
`|| true`は、ファイルが読めないような本当の失敗まで隠してしまうためです。

```bash
# grepは一致が無ければ1を、エラーなら2を返すので、1だけを許します。
matches=$(grep foo input.txt) || [ $? -eq 1 ]
```

`mkdir -p`のように、既にその状態になっていることを許すオプションがあるコマンドは、そのオプションを使います。

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in data-ai →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.