---
title: "エラー処理を設計・実装する（エージェント用スキル） | Orchestor"
description: "例外、Result 型、エラーの伝播、段階的な機能縮退など、言語をまたぐエラー処理のパターンを適用します。エラー処理の実装、API 設計、アプリケーションの信頼性改善に使います。wshobson/agents が公開している「エラー処理を設計・実装する」の使い方を確認できます。"
canonical_url: "https://www.orchestor.io/ja/skills/wshobson/agents/error-handling-patterns"
markdown_url: "https://www.orchestor.io/ja/skills/wshobson/agents/error-handling-patterns.md"
---

[c96b5f6](https://github.com/wshobson/agents/commit/c96b5f6552dba32e4492307493ee613581430715)[原文を開く](https://github.com/wshobson/agents/blob/c96b5f6552dba32e4492307493ee613581430715/plugins/developer-essentials/skills/error-handling-patterns/SKILL.md)

wshobson2026/11/24

原文 (選択中)

未翻訳

プレビュー (選択中)

121 行（空行を除く 94 行） · 3.99 KB原文

```yaml
name: error-handling-patterns
description: Master error handling patterns across languages including exceptions, Result types, error propagation, and graceful degradation to build resilient applications. Use when implementing error handling, designing APIs, or improving application reliability.
```

# Error Handling Patterns

Build resilient applications with robust error handling strategies that gracefully handle failures and provide excellent debugging experiences.

## When to Use This Skill

* Implementing error handling in new features
* Designing error-resilient APIs
* Debugging production issues
* Improving application reliability
* Creating better error messages for users and developers
* Implementing retry and circuit breaker patterns
* Handling async/concurrent errors
* Building fault-tolerant distributed systems

## Core Concepts

### 1\. Error Handling Philosophies

**Exceptions vs Result Types:**

* **Exceptions**: Traditional try-catch, disrupts control flow
* **Result Types**: Explicit success/failure, functional approach
* **Error Codes**: C-style, requires discipline
* **Option/Maybe Types**: For nullable values

**When to Use Each:**

* Exceptions: Unexpected errors, exceptional conditions
* Result Types: Expected errors, validation failures
* Panics/Crashes: Unrecoverable errors, programming bugs

### 2\. Error Categories

**Recoverable Errors:**

* Network timeouts
* Missing files
* Invalid user input
* API rate limits

**Unrecoverable Errors:**

* Out of memory
* Stack overflow
* Programming bugs (null pointer, etc.)

## Detailed patterns and worked examples

Detailed pattern documentation lives in details.md. Read that file when the navigation tier above is insufficient.

## Best Practices

1. **Fail Fast**: Validate input early, fail quickly
2. **Preserve Context**: Include stack traces, metadata, timestamps
3. **Meaningful Messages**: Explain what happened and how to fix it
4. **Log Appropriately**: Error = log, expected failure = don't spam logs
5. **Handle at Right Level**: Catch where you can meaningfully handle
6. **Clean Up Resources**: Use try-finally, context managers, defer
7. **Don't Swallow Errors**: Log or re-throw, don't silently ignore
8. **Type-Safe Errors**: Use typed errors when possible

```python
# Good error handling example
def process_order(order_id: str) -> Order:
    """Process order with comprehensive error handling."""
    try:
        # Validate input
        if not order_id:
            raise ValidationError("Order ID is required")
​
        # Fetch order
        order = db.get_order(order_id)
        if not order:
            raise NotFoundError("Order", order_id)
​
        # Process payment
        try:
            payment_result = payment_service.charge(order.total)
        except PaymentServiceError as e:
            # Log and wrap external service error
            logger.error(f"Payment failed for order {order_id}: {e}")
            raise ExternalServiceError(
                f"Payment processing failed",
                service="payment_service",
                details={"order_id": order_id, "amount": order.total}
            ) from e
​
        # Update order
        order.status = "completed"
        order.payment_id = payment_result.id
        db.save(order)
​
        return order
​
    except ApplicationError:
        # Re-raise known application errors
        raise
    except Exception as e:
        # Log unexpected errors
        logger.exception(f"Unexpected error processing order {order_id}")
        raise ApplicationError(
            "Order processing failed",
            code="INTERNAL_ERROR"
        ) from e
```

## Common Pitfalls

* **Catching Too Broadly**: `except Exception` hides bugs
* **Empty Catch Blocks**: Silently swallowing errors
* **Logging and Re-throwing**: Creates duplicate log entries
* **Not Cleaning Up**: Forgetting to close files, connections
* **Poor Error Messages**: "Error occurred" is not helpful
* **Returning Error Codes**: Use exceptions or Result types
* **Ignoring Async Errors**: Unhandled promise rejections

## Structured data

```json
[
  [
    {
      "@context": "https://schema.org",
      "@type": "Organization",
      "name": "Orchestor",
      "url": "https://www.orchestor.io",
      "sameAs": [
        "https://orchestor.io",
        "https://www.orchestor.io",
        "https://docs.orchestor.io"
      ],
      "@id": "https://www.orchestor.io/#organization",
      "alternateName": [
        "オーケスター"
      ],
      "logo": "https://www.orchestor.io/images/common/ogp/orchestor-ogp.png",
      "parentOrganization": {
        "@type": "Organization",
        "name": "ドットメディア株式会社",
        "url": "https://www.dotmedia.co.jp"
      }
    },
    {
      "@context": "https://schema.org",
      "@type": "WebSite",
      "url": "https://www.orchestor.io",
      "name": "Orchestor",
      "description": "Orchestor で画像・動画・音声を作り、参照素材を Remix できます。",
      "@id": "https://www.orchestor.io/#website",
      "alternateName": [
        "オーケスター"
      ],
      "inLanguage": "ja",
      "publisher": {
        "@id": "https://www.orchestor.io/#organization"
      }
    }
  ],
  {
    "@context": "https://schema.org",
    "@type": "BreadcrumbList",
    "@id": "https://www.orchestor.io/skills/wshobson/agents/error-handling-patterns#breadcrumb",
    "itemListElement": [
      {
        "@type": "ListItem",
        "position": 1,
        "name": "Orchestor",
        "item": "https://www.orchestor.io/"
      },
      {
        "@type": "ListItem",
        "position": 2,
        "name": "スキル",
        "item": "https://www.orchestor.io/skills"
      },
      {
        "@type": "ListItem",
        "position": 3,
        "name": "エラー処理を設計・実装する",
        "item": "https://www.orchestor.io/skills/wshobson/agents/error-handling-patterns"
      }
    ]
  }
]
```

---

[Documentation index](https://www.orchestor.io/llms.txt)
