fvtt-error-handling
This skill should be used when adding error handling to catch blocks, standardizing error handling across a codebase, or ensuring proper UX with user messages vs technical logs. Covers NotificationOptions, Hooks.onError, and preventing console noise.
What this skill does
# Foundry VTT Error Handling Patterns
**Domain:** Foundry VTT V12/V13 Error Handling
**Status:** Production-Ready (Verified against V13 API)
**Last Updated:** 2025-12-31
---
## Overview
This skill provides **production-ready error handling patterns** for Foundry VTT modules, using the documented V13 APIs: `NotificationOptions` and `Hooks.onError`.
### When to Use This Skill
- Adding error handling to catch blocks in Foundry modules
- Standardizing error handling across a codebase
- Ensuring proper UX (user messages vs technical logs)
- Preventing console noise and double-logging
- Enabling ecosystem compatibility (other modules can listen to your errors)
### Core Principle
**Always separate error funnel from user notification:**
- **Error funnel** (`Hooks.onError`): Logs stack traces, triggers ecosystem hooks, provides structured data
- **User notification** (`ui.notifications.*`): Clean, sanitized messages with full UX control
**Why separation matters:**
1. `Hooks.onError` mutates `error.message` when `msg` is provided (see Foundry GitHub #6669)
2. `clean: true` only works in NotificationOptions, not Hooks.onError
3. User sees only your controlled message, not technical details
4. Explicit control over console logging (`console: false` prevents double-logging)
---
## Quick Reference: Four Error Patterns
| Pattern | Error Funnel | User Notification | Use Case |
|---------|--------------|-------------------|----------|
| **User-facing** | Hooks.onError (`notify: null`) | ui.notifications.error | Unexpected failures |
| **Expected validation** | _(none)_ | ui.notifications.warn | User input errors |
| **Developer-only** | Hooks.onError (`notify: null`) | _(none)_ | Diagnostic logging |
| **High-frequency** | Throttled Hooks.onError | Throttled ui.notifications.warn | Render loops, hooks |
---
## Pattern 1: User-Facing Failures
**Use for:** Unexpected errors, operations that failed, critical failures
```javascript
} catch (err) {
// Preserve original error as cause when wrapping non-Errors
const error = err instanceof Error ? err : new Error(String(err), { cause: err });
// Error funnel: stack traces + ecosystem hooks (no UI)
Hooks.onError(`YourModule.${contextDescription}`, error, {
msg: "[YourModule]",
log: "error",
notify: null, // No UI from hook
data: { contextDescription, userFacingDescription } // Structured context
});
// Fully controlled user message (sanitized, no console - already logged)
ui.notifications.error(`[YourModule] ${userFacingDescription}`, {
clean: true,
console: false // Hooks.onError already logged
});
}
```
**Key points:**
- User sees only `userFacingDescription` (no technical details leaked)
- Stack trace logged via Hooks.onError (full Error object)
- Ecosystem visibility (other modules can listen to `Hooks.on("error", ...)`)
- Structured `data` for debugging and hook subscribers
- Explicit `console: false` prevents double-logging
---
## Pattern 2: Expected Validation / Recoverable Issues
**Use for:** User input errors, missing data, expected validation failures
```javascript
} catch (err) {
const message = `[YourModule] ${userFacingDescription}`;
ui.notifications.warn(message, {
clean: true,
console: false // Expected failures - no console noise
});
}
```
**Key points:**
- Uses `warn` severity (not `error`) for expected cases
- Simpler than Hooks.onError (no error funnel needed for routine validation)
- `console: false` avoids noise for common user-driven failures
- **Optional**: Gate console logging behind debug flag:
```javascript
console: game.settings.get("your-module", "enableProfiling")
```
---
## Pattern 3: Developer-Only Errors
**Use for:** Diagnostic logging, internal errors that don't need user notification
```javascript
} catch (err) {
const error = err instanceof Error ? err : new Error(String(err), { cause: err });
Hooks.onError(`YourModule.${contextDescription}`, error, {
msg: "[YourModule]",
log: "error",
notify: null, // Log only, no UI spam
data: { contextDescription } // Structured context for debugging
});
}
```
**Key points:**
- Uses error funnel (consistency) but no notification
- Stack traces logged for developers
- No UI spam for internal diagnostics
- **Alternative**: Use `console.error(...)` for truly isolated cases (but lose ecosystem hooks)
---
## Pattern 4: High-Frequency Errors
**Use for:** Render loops, hooks, event handlers that might error repeatedly
```javascript
// Module-scoped throttle (outside class/function)
const errorThrottles = new Map();
// In catch block:
} catch (err) {
const throttleKey = contextDescription;
const lastError = errorThrottles.get(throttleKey) || 0;
// Throttle: 5 second window per context
if (Date.now() - lastError > 5000) {
const error = err instanceof Error ? err : new Error(String(err), { cause: err });
// Error funnel (no UI)
Hooks.onError(`YourModule.${contextDescription}`, error, {
msg: "[YourModule]",
log: "warn",
notify: null, // No UI from hook
data: { contextDescription, userFacingDescription }
});
// Separate controlled notification (console: false prevents double-logging)
ui.notifications.warn(`[YourModule] ${userFacingDescription}`, {
clean: true,
console: false // Already logged via Hooks.onError
});
errorThrottles.set(throttleKey, Date.now());
}
}
```
**Key points:**
- Throttles to prevent notification queue flood
- Module-scoped Map prevents spam across multiple instances
- Uses `warn` severity for non-critical repeated errors
- Separates error funnel (logs only) from user notification
- Explicit `console: false` prevents double-logging
---
## Decision Tree: Classifying Errors
**Ask these questions:**
1. **Is this unexpected?** (system failure, unhandled case, critical error)
→ **Pattern 1**: User-facing failures
2. **Is this expected validation?** (user input error, missing required data)
→ **Pattern 2**: Expected validation
3. **Is this diagnostic-only?** (internal state, no user impact)
→ **Pattern 3**: Developer-only
4. **Could this fire repeatedly?** (render loop, hook, event handler)
→ **Pattern 4**: High-frequency throttled
---
## Foundry-Specific Gotchas
### 1. `Hooks.onError` Mutates Error Objects
**Critical**: `Hooks.onError` modifies `error.message` when `msg` is provided:
```javascript
// Internal Foundry implementation (from GitHub #6669):
if (msg) err.message = `${msg}: ${err.message}`;
```
**This is why we separate funnel from notification:**
- Error funnel gets the Error object (stack traces preserved)
- User notification uses clean string (no mutation affects UX)
**Always normalize to Error objects:**
```javascript
const error = err instanceof Error ? err : new Error(String(err), { cause: err });
```
### 2. `console` Default Behavior Not Documented
**Issue**: Foundry V13 docs don't explicitly state the default value for `NotificationOptions.console`.
**Evidence**: API examples show `{ console: false }` to suppress logging, implying default is `true`.
**Best practice**: Be explicit to prevent double-logging and future-proof against default changes:
```javascript
ui.notifications.error(message, {
clean: true,
console: false // Explicit is better than implicit
});
```
### 3. `notify` String Values Are Undocumented
**Issue**: `Hooks.onError` accepts `notify: null | string`, but valid string values aren't enumerated in V13 API docs.
**Your assumption**: `notify` accepts `"error"`, `"warn"`, `"info"` (like `ui.notifications.*` methods)
**Reality**: Likely correct but NOT explicitly documented.
**Best practice**: Use `notify: null` + separate `ui.notifications.*` for full control:
```javascript
// Avoid relying on undocumented notify strings
Hooks.onError(..., { notify: null }); // Error funnel only
ui.notifications.error(...); // Separate notification
```
### 4. `clean: true` Only WRelated in Design
contribute
IncludedLocal-only OSS contribution command center. Auto-refreshes the user's in-flight PR and issue state on invoke so conversations start with full context — no need to brief Claude on what's in flight. Helps the user find issues to contribute to on GitHub, builds per-repo dossiers of what each upstream expects (CLA, DCO, branch convention, AI policy, draft-first, review bots, issue templates), runs deterministic gates before any external action so AI-assisted contributions don't reach maintainers as slop. State is markdown-only: candidate files at ~/.contribute-system/candidates/, repo dossiers at ~/.contribute-system/research/, append-only event log at ~/.contribute-system/log.jsonl. No database, no cloud calls. Use when the user asks about their PRs / issues / contributions, wants to find new work to take on, claim an issue, build/refresh a repo's dossier, or draft a Design Issue or PR. Trigger with "/contribute", "what's my PR status", "find a contribution", "claim issue X", "draft a Design Issue for Y", "refresh dossier for Z".
architectural-analysis
IncludedUser-triggered deep architectural analysis of a codebase or scoped subtree across eight modes — information architecture, data flow, integration points, UI surfaces, interaction patterns, data model, control flow, and failure modes. This skill should be used when the user asks to "diagram this codebase," "map the architecture," "show the data flow," "give me an ERD," "trace control flow," "find the integration points," "verify the layout pattern," "audit the UX architecture," or any similar request whose primary deliverable is mermaid diagrams plus cited reports under docs/architecture/. Dispatches haiku/sonnet sub-agents in parallel for per-mode exploration, then verifies every citation mechanically before any node lands in a diagram. Not for one-off prose explanations of code (use code-explanation) or for high-level system design from scratch (use system-design).
mcp
IncludedModel Context Protocol (MCP) server development and tool management. Languages: Python, TypeScript. Capabilities: build MCP servers, integrate external APIs, discover/execute MCP tools, manage multi-server configs, design agent-centric tools. Actions: create, build, integrate, discover, execute, configure MCP servers/tools. Keywords: MCP, Model Context Protocol, MCP server, MCP tool, stdio transport, SSE transport, tool discovery, resource provider, prompt template, external API integration, Gemini CLI MCP, Claude MCP, agent tools, tool execution, server config. Use when: building MCP servers, integrating external APIs as MCP tools, discovering available MCP tools, executing MCP capabilities, configuring multi-server setups, designing tools for AI agents.
react-native-skia
IncludedDesign, build, debug, and optimise high-polish animated graphics in React Native or Expo using @shopify/react-native-skia, Reanimated, and Gesture Handler. Use when the user wants canvas-driven UI, shaders, paths, rich text, image filters, sprite fields, Skottie, video frames, snapshots, web CanvasKit setup, or performance tuning for custom motion-heavy elements such as loaders, hero art, cards, charts, progress indicators, particle systems, or gesture-driven surfaces. Also use when the user asks for fluid, glow, glass, blob, parallax, 60fps/120fps, or GPU-friendly animated effects in React Native, even if they do not explicitly say "Skia". Do not use for ordinary form/layout work with standard views.
plaid
IncludedProduct Led AI Development — guides founders from idea to launched product. Six capabilities: Idea (discover a product idea), Validate (pressure-test the idea against fatal flaws, problem reality, competition, and 2-week MVP feasibility), Plan (vision intake + document generation), Design (translate image references into a design.md spec), Launch (go-to-market strategy), and Build (roadmap execution). Use when someone says "PLAID", "plaid idea", "help me find an idea", "product idea", "idea from my business", "idea from my expertise", "plaid validate", "validate my idea", "pressure-test", "is this idea good", "find fatal flaws", "validate the problem", "plan a product", "define my vision", "generate a PRD", "product strategy", "plaid design", "design from image", "translate image to design", "create design.md", "extract design tokens", "plaid launch", "go-to-market", "launch plan", "GTM strategy", "launch playbook", "plaid build", "build the app", "start building", or "execute the roadmap".
nextjs-framer-motion-animations
IncludedAdds production-safe Motion for React or Framer Motion animations to Next.js apps, including reveal, hover and tap micro-interactions, whileInView, stagger, AnimatePresence, layout and layoutId transitions, reorder, scroll-linked UI, and lightweight route-content transitions. Use when the user asks to add, refactor, or debug Motion or Framer Motion in App Router or Pages Router codebases, especially around server/client boundaries, reduced motion, LazyMotion, bundle size, hydration, or route transitions. Avoid for GSAP-style timelines, WebGL or 3D scenes, heavy scroll storytelling, or CSS-only effects unless Motion is explicitly requested.