claude-all-config 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/LICENSE +21 -0
  2. package/LICENSE.md +70 -0
  3. package/README.md +133 -0
  4. package/VERSION +1 -0
  5. package/agents/accessibility-reviewer.md +96 -0
  6. package/agents/ai-prompt-optimizer.md +94 -0
  7. package/agents/api-tester.md +102 -0
  8. package/agents/code-generator.md +94 -0
  9. package/agents/code-reviewer.md +47 -0
  10. package/agents/component-generator.md +102 -0
  11. package/agents/doc-generator.md +91 -0
  12. package/agents/migration-generator.md +94 -0
  13. package/agents/performance-analyzer.md +90 -0
  14. package/agents/proactive-mode.md +91 -0
  15. package/agents/readme-generator.md +101 -0
  16. package/agents/security-auditor.md +86 -0
  17. package/agents/terraform-generator.md +94 -0
  18. package/agents/test-generator.md +76 -0
  19. package/bin/agentrouter.json +36 -0
  20. package/bin/ai-chat +20 -0
  21. package/bin/antigravity.json +76 -0
  22. package/bin/api-manager +340 -0
  23. package/bin/claude-launcher +19 -0
  24. package/bin/claude-master +15 -0
  25. package/bin/claude_master.py +295 -0
  26. package/bin/cohere.json +7 -0
  27. package/bin/deepseek.json +44 -0
  28. package/bin/gemini.json +56 -0
  29. package/bin/glm.json +21 -0
  30. package/bin/groq.json +41 -0
  31. package/bin/minimax.json +26 -0
  32. package/bin/mistral.json +7 -0
  33. package/bin/moonshot.json +7 -0
  34. package/bin/ollama.json +36 -0
  35. package/bin/openai.json +46 -0
  36. package/bin/openrouter.json +38 -0
  37. package/bin/perplexity.json +12 -0
  38. package/bin/qwen.json +7 -0
  39. package/bin/switch-provider +73 -0
  40. package/bin/test.json +7 -0
  41. package/bin/xai.json +41 -0
  42. package/claude-all +2707 -0
  43. package/claude-config.json +340 -0
  44. package/claude-suite/REFACTORING_SUMMARY.md +88 -0
  45. package/claude-suite/auth/.antigravity_proxy.py +78 -0
  46. package/claude-suite/auth/__pycache__/openai_auth.cpython-312.pyc +0 -0
  47. package/claude-suite/auth/gemini_auth.py +80 -0
  48. package/claude-suite/auth/openai_auth.py +138 -0
  49. package/claude-suite/backups/claude-all-before-refactor +1075 -0
  50. package/claude-suite/backups/claude-all.backup +840 -0
  51. package/claude-suite/backups/claude-all.original +840 -0
  52. package/claude-suite/models/add-model-manual.sh +588 -0
  53. package/claude-suite/models/add-model.sh +114 -0
  54. package/claude-suite/models/model-switcher.sh +69 -0
  55. package/claude-suite/providers/claude-glm +89 -0
  56. package/claude-suite/providers/claude-glm-wrapper.sh +55 -0
  57. package/claude-suite/providers/claude-minimax +12 -0
  58. package/claude-suite/providers/claude-smart +132 -0
  59. package/claude-suite/providers/xai_chat.sh +56 -0
  60. package/claude-suite/utils/__pycache__/claude_master.cpython-312.pyc +0 -0
  61. package/claude-suite/utils/antigravity_proxy_server.py +168 -0
  62. package/claude-suite/utils/claude-all-help.txt +83 -0
  63. package/claude-suite/utils/claude_master.py +408 -0
  64. package/commands/brainstorm.md +5 -0
  65. package/commands/execute-plan.md +5 -0
  66. package/commands/write-plan.md +5 -0
  67. package/docs/ANTIGRAVITY-SETUP.md +176 -0
  68. package/docs/AUTH_CREDENTIALS.md +54 -0
  69. package/docs/NPM-INSTALLATION.md +166 -0
  70. package/hooks/hooks.json +15 -0
  71. package/hooks/run-hook.cmd +19 -0
  72. package/hooks/session-start.sh +52 -0
  73. package/install.sh +155 -0
  74. package/mcp.json +34 -0
  75. package/model/perplexity.json +12 -0
  76. package/package.json +69 -0
  77. package/plugins/README.md +47 -0
  78. package/plugins/installed_plugins.json +317 -0
  79. package/plugins/known_marketplaces.json +10 -0
  80. package/plugins/marketplace-info/marketplace.json +517 -0
  81. package/postinstall.js +100 -0
  82. package/scripts/antigravity_proxy_server.py +168 -0
  83. package/scripts/get_gemini_api_key.py +96 -0
  84. package/scripts/setup_antigravity_auth.py +171 -0
  85. package/skills/api-development/SKILL.md +11 -0
  86. package/skills/api-development/openapi/api-documentation.yaml +108 -0
  87. package/skills/brainstorming/SKILL.md +54 -0
  88. package/skills/code-quality/SKILL.md +196 -0
  89. package/skills/condition-based-waiting/SKILL.md +120 -0
  90. package/skills/condition-based-waiting/example.ts +158 -0
  91. package/skills/database-development/SKILL.md +11 -0
  92. package/skills/database-development/migrations/migration.template.sql +49 -0
  93. package/skills/defense-in-depth/SKILL.md +127 -0
  94. package/skills/deployment/SKILL.md +11 -0
  95. package/skills/deployment/ci-cd/github-actions.yml +95 -0
  96. package/skills/deployment/docker/Dockerfile.template +39 -0
  97. package/skills/dispatching-parallel-agents/SKILL.md +180 -0
  98. package/skills/documentation-generation/SKILL.md +8 -0
  99. package/skills/documentation-generation/templates/README.template.md +60 -0
  100. package/skills/error-handling/SKILL.md +267 -0
  101. package/skills/executing-plans/SKILL.md +76 -0
  102. package/skills/finishing-a-development-branch/SKILL.md +200 -0
  103. package/skills/frontend-design/frontend-design/SKILL.md +42 -0
  104. package/skills/integration-testing/SKILL.md +13 -0
  105. package/skills/integration-testing/examples/contract-test.py +317 -0
  106. package/skills/integration-testing/examples/e2e-test.js +147 -0
  107. package/skills/integration-testing/examples/test-isolation.md +94 -0
  108. package/skills/logging-monitoring/SKILL.md +66 -0
  109. package/skills/mobile-development/SKILL.md +11 -0
  110. package/skills/mobile-development/responsive/responsive.css +80 -0
  111. package/skills/performance-optimization/SKILL.md +9 -0
  112. package/skills/performance-optimization/profiling/profile.template.js +21 -0
  113. package/skills/receiving-code-review/SKILL.md +209 -0
  114. package/skills/refactoring/SKILL.md +11 -0
  115. package/skills/refactoring/code-smells/common-smells.md +115 -0
  116. package/skills/requesting-code-review/SKILL.md +105 -0
  117. package/skills/requesting-code-review/code-reviewer.md +146 -0
  118. package/skills/root-cause-tracing/SKILL.md +174 -0
  119. package/skills/root-cause-tracing/find-polluter.sh +63 -0
  120. package/skills/security-review/SKILL.md +11 -0
  121. package/skills/security-review/checklists/owasp-checklist.md +31 -0
  122. package/skills/sharing-skills/SKILL.md +194 -0
  123. package/skills/subagent-driven-development/SKILL.md +240 -0
  124. package/skills/subagent-driven-development/code-quality-reviewer-prompt.md +20 -0
  125. package/skills/subagent-driven-development/implementer-prompt.md +78 -0
  126. package/skills/subagent-driven-development/spec-reviewer-prompt.md +61 -0
  127. package/skills/systematic-debugging/CREATION-LOG.md +119 -0
  128. package/skills/systematic-debugging/SKILL.md +295 -0
  129. package/skills/systematic-debugging/test-academic.md +14 -0
  130. package/skills/systematic-debugging/test-pressure-1.md +58 -0
  131. package/skills/systematic-debugging/test-pressure-2.md +68 -0
  132. package/skills/systematic-debugging/test-pressure-3.md +69 -0
  133. package/skills/test-driven-development/SKILL.md +364 -0
  134. package/skills/testing-anti-patterns/SKILL.md +302 -0
  135. package/skills/testing-skills-with-subagents/SKILL.md +387 -0
  136. package/skills/testing-skills-with-subagents/examples/CLAUDE_MD_TESTING.md +189 -0
  137. package/skills/ui-ux-review/SKILL.md +13 -0
  138. package/skills/ui-ux-review/checklists/ux-heuristics.md +61 -0
  139. package/skills/using-git-worktrees/SKILL.md +213 -0
  140. package/skills/using-superpowers/SKILL.md +101 -0
  141. package/skills/verification-before-completion/SKILL.md +139 -0
  142. package/skills/writing-plans/SKILL.md +116 -0
  143. package/skills/writing-skills/SKILL.md +622 -0
  144. package/skills/writing-skills/anthropic-best-practices.md +1150 -0
  145. package/skills/writing-skills/graphviz-conventions.dot +172 -0
  146. package/skills/writing-skills/persuasion-principles.md +187 -0
  147. package/update.sh +36 -0
  148. package/utils/check-superpowers.sh +114 -0
  149. package/utils/claude-branding.md +166 -0
  150. package/utils/config.js +185 -0
  151. package/utils/custom-claude-config.sh +89 -0
  152. package/utils/custom-claude-hooks.md +129 -0
  153. package/utils/custom-claude-lib.js +222 -0
  154. package/utils/customize-claude-ui.sh +162 -0
  155. package/utils/fix-claude-integration.sh +133 -0
  156. package/utils/help.js +125 -0
  157. package/utils/install-curl.ps1 +135 -0
  158. package/utils/install-curl.sh +525 -0
  159. package/utils/install-superpowers.js +411 -0
  160. package/utils/install.js +298 -0
  161. package/utils/install.sh +182 -0
  162. package/utils/postinstall.js +63 -0
  163. package/utils/rename-claude.sh +96 -0
  164. package/utils/uninstall-superpowers.js +273 -0
  165. package/utils/uninstall.ps1 +136 -0
  166. package/utils/uninstall.sh +163 -0
  167. package/utils/update.sh +160 -0
@@ -0,0 +1,95 @@
1
+ name: CI/CD Pipeline
2
+
3
+ on:
4
+ push:
5
+ branches: [ main, develop ]
6
+ pull_request:
7
+ branches: [ main ]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ node-version: [18.x, 20.x]
15
+
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - name: Setup Node.js
20
+ uses: actions/setup-node@v4
21
+ with:
22
+ node-version: ${{ matrix.node-version }}
23
+ cache: 'npm'
24
+
25
+ - name: Install dependencies
26
+ run: npm ci
27
+
28
+ - name: Run linting
29
+ run: npm run lint
30
+
31
+ - name: Run type checking
32
+ run: npm run type-check
33
+
34
+ - name: Run tests
35
+ run: npm run test
36
+
37
+ - name: Run e2e tests
38
+ run: npm run test:e2e
39
+
40
+ security:
41
+ runs-on: ubuntu-latest
42
+ steps:
43
+ - uses: actions/checkout@v4
44
+
45
+ - name: Run security audit
46
+ run: npm audit --audit-level=high
47
+
48
+ - name: Run Snyk security scan
49
+ uses: snyk/actions/node@master
50
+ env:
51
+ SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
52
+
53
+ build:
54
+ needs: [test, security]
55
+ runs-on: ubuntu-latest
56
+
57
+ steps:
58
+ - uses: actions/checkout@v4
59
+
60
+ - name: Setup Node.js
61
+ uses: actions/setup-node@v4
62
+ with:
63
+ node-version: '20.x'
64
+ cache: 'npm'
65
+
66
+ - name: Install dependencies
67
+ run: npm ci
68
+
69
+ - name: Build application
70
+ run: npm run build
71
+
72
+ - name: Upload build artifacts
73
+ uses: actions/upload-artifact@v4
74
+ with:
75
+ name: build-artifacts
76
+ path: dist/
77
+
78
+ deploy:
79
+ needs: build
80
+ runs-on: ubuntu-latest
81
+ if: github.ref == 'refs/heads/main'
82
+
83
+ environment: production
84
+
85
+ steps:
86
+ - name: Download build artifacts
87
+ uses: actions/download-artifact@v4
88
+ with:
89
+ name: build-artifacts
90
+ path: dist/
91
+
92
+ - name: Deploy to production
93
+ run: |
94
+ echo "Deploy to production server"
95
+ # Add deployment commands here
@@ -0,0 +1,39 @@
1
+ # Multi-stage build for optimal image size
2
+ FROM node:18-alpine AS builder
3
+
4
+ WORKDIR /app
5
+ COPY package*.json ./
6
+ RUN npm ci --only=production
7
+
8
+ # Copy source code
9
+ COPY . .
10
+
11
+ # Build application
12
+ RUN npm run build
13
+
14
+ # Production stage
15
+ FROM node:18-alpine AS production
16
+
17
+ # Create app user
18
+ RUN addgroup -g 1001 -S nodejs
19
+ RUN adduser -S nextjs -u 1001
20
+
21
+ WORKDIR /app
22
+
23
+ # Copy built application
24
+ COPY --from=builder --chown=nextjs:nodejs /app/dist ./dist
25
+ COPY --from=builder /app/node_modules ./node_modules
26
+ COPY --from=builder /app/package.json ./package.json
27
+
28
+ # Health check
29
+ HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
30
+ CMD curl -f http://localhost:3000/health || exit 1
31
+
32
+ USER nextjs
33
+
34
+ EXPOSE 3000
35
+
36
+ ENV NODE_ENV=production
37
+ ENV PORT=3000
38
+
39
+ CMD ["npm", "start"]
@@ -0,0 +1,180 @@
1
+ ---
2
+ name: dispatching-parallel-agents
3
+ description: Use when facing 3+ independent failures that can be investigated without shared state or dependencies - dispatches multiple Claude agents to investigate and fix independent problems concurrently
4
+ ---
5
+
6
+ # Dispatching Parallel Agents
7
+
8
+ ## Overview
9
+
10
+ When you have multiple unrelated failures (different test files, different subsystems, different bugs), investigating them sequentially wastes time. Each investigation is independent and can happen in parallel.
11
+
12
+ **Core principle:** Dispatch one agent per independent problem domain. Let them work concurrently.
13
+
14
+ ## When to Use
15
+
16
+ ```dot
17
+ digraph when_to_use {
18
+ "Multiple failures?" [shape=diamond];
19
+ "Are they independent?" [shape=diamond];
20
+ "Single agent investigates all" [shape=box];
21
+ "One agent per problem domain" [shape=box];
22
+ "Can they work in parallel?" [shape=diamond];
23
+ "Sequential agents" [shape=box];
24
+ "Parallel dispatch" [shape=box];
25
+
26
+ "Multiple failures?" -> "Are they independent?" [label="yes"];
27
+ "Are they independent?" -> "Single agent investigates all" [label="no - related"];
28
+ "Are they independent?" -> "Can they work in parallel?" [label="yes"];
29
+ "Can they work in parallel?" -> "Parallel dispatch" [label="yes"];
30
+ "Can they work in parallel?" -> "Sequential agents" [label="no - shared state"];
31
+ }
32
+ ```
33
+
34
+ **Use when:**
35
+ - 3+ test files failing with different root causes
36
+ - Multiple subsystems broken independently
37
+ - Each problem can be understood without context from others
38
+ - No shared state between investigations
39
+
40
+ **Don't use when:**
41
+ - Failures are related (fix one might fix others)
42
+ - Need to understand full system state
43
+ - Agents would interfere with each other
44
+
45
+ ## The Pattern
46
+
47
+ ### 1. Identify Independent Domains
48
+
49
+ Group failures by what's broken:
50
+ - File A tests: Tool approval flow
51
+ - File B tests: Batch completion behavior
52
+ - File C tests: Abort functionality
53
+
54
+ Each domain is independent - fixing tool approval doesn't affect abort tests.
55
+
56
+ ### 2. Create Focused Agent Tasks
57
+
58
+ Each agent gets:
59
+ - **Specific scope:** One test file or subsystem
60
+ - **Clear goal:** Make these tests pass
61
+ - **Constraints:** Don't change other code
62
+ - **Expected output:** Summary of what you found and fixed
63
+
64
+ ### 3. Dispatch in Parallel
65
+
66
+ ```typescript
67
+ // In Claude Code / AI environment
68
+ Task("Fix agent-tool-abort.test.ts failures")
69
+ Task("Fix batch-completion-behavior.test.ts failures")
70
+ Task("Fix tool-approval-race-conditions.test.ts failures")
71
+ // All three run concurrently
72
+ ```
73
+
74
+ ### 4. Review and Integrate
75
+
76
+ When agents return:
77
+ - Read each summary
78
+ - Verify fixes don't conflict
79
+ - Run full test suite
80
+ - Integrate all changes
81
+
82
+ ## Agent Prompt Structure
83
+
84
+ Good agent prompts are:
85
+ 1. **Focused** - One clear problem domain
86
+ 2. **Self-contained** - All context needed to understand the problem
87
+ 3. **Specific about output** - What should the agent return?
88
+
89
+ ```markdown
90
+ Fix the 3 failing tests in src/agents/agent-tool-abort.test.ts:
91
+
92
+ 1. "should abort tool with partial output capture" - expects 'interrupted at' in message
93
+ 2. "should handle mixed completed and aborted tools" - fast tool aborted instead of completed
94
+ 3. "should properly track pendingToolCount" - expects 3 results but gets 0
95
+
96
+ These are timing/race condition issues. Your task:
97
+
98
+ 1. Read the test file and understand what each test verifies
99
+ 2. Identify root cause - timing issues or actual bugs?
100
+ 3. Fix by:
101
+ - Replacing arbitrary timeouts with event-based waiting
102
+ - Fixing bugs in abort implementation if found
103
+ - Adjusting test expectations if testing changed behavior
104
+
105
+ Do NOT just increase timeouts - find the real issue.
106
+
107
+ Return: Summary of what you found and what you fixed.
108
+ ```
109
+
110
+ ## Common Mistakes
111
+
112
+ **❌ Too broad:** "Fix all the tests" - agent gets lost
113
+ **✅ Specific:** "Fix agent-tool-abort.test.ts" - focused scope
114
+
115
+ **❌ No context:** "Fix the race condition" - agent doesn't know where
116
+ **✅ Context:** Paste the error messages and test names
117
+
118
+ **❌ No constraints:** Agent might refactor everything
119
+ **✅ Constraints:** "Do NOT change production code" or "Fix tests only"
120
+
121
+ **❌ Vague output:** "Fix it" - you don't know what changed
122
+ **✅ Specific:** "Return summary of root cause and changes"
123
+
124
+ ## When NOT to Use
125
+
126
+ **Related failures:** Fixing one might fix others - investigate together first
127
+ **Need full context:** Understanding requires seeing entire system
128
+ **Exploratory debugging:** You don't know what's broken yet
129
+ **Shared state:** Agents would interfere (editing same files, using same resources)
130
+
131
+ ## Real Example from Session
132
+
133
+ **Scenario:** 6 test failures across 3 files after major refactoring
134
+
135
+ **Failures:**
136
+ - agent-tool-abort.test.ts: 3 failures (timing issues)
137
+ - batch-completion-behavior.test.ts: 2 failures (tools not executing)
138
+ - tool-approval-race-conditions.test.ts: 1 failure (execution count = 0)
139
+
140
+ **Decision:** Independent domains - abort logic separate from batch completion separate from race conditions
141
+
142
+ **Dispatch:**
143
+ ```
144
+ Agent 1 → Fix agent-tool-abort.test.ts
145
+ Agent 2 → Fix batch-completion-behavior.test.ts
146
+ Agent 3 → Fix tool-approval-race-conditions.test.ts
147
+ ```
148
+
149
+ **Results:**
150
+ - Agent 1: Replaced timeouts with event-based waiting
151
+ - Agent 2: Fixed event structure bug (threadId in wrong place)
152
+ - Agent 3: Added wait for async tool execution to complete
153
+
154
+ **Integration:** All fixes independent, no conflicts, full suite green
155
+
156
+ **Time saved:** 3 problems solved in parallel vs sequentially
157
+
158
+ ## Key Benefits
159
+
160
+ 1. **Parallelization** - Multiple investigations happen simultaneously
161
+ 2. **Focus** - Each agent has narrow scope, less context to track
162
+ 3. **Independence** - Agents don't interfere with each other
163
+ 4. **Speed** - 3 problems solved in time of 1
164
+
165
+ ## Verification
166
+
167
+ After agents return:
168
+ 1. **Review each summary** - Understand what changed
169
+ 2. **Check for conflicts** - Did agents edit same code?
170
+ 3. **Run full suite** - Verify all fixes work together
171
+ 4. **Spot check** - Agents can make systematic errors
172
+
173
+ ## Real-World Impact
174
+
175
+ From debugging session (2025-10-03):
176
+ - 6 failures across 3 files
177
+ - 3 agents dispatched in parallel
178
+ - All investigations completed concurrently
179
+ - All fixes integrated successfully
180
+ - Zero conflicts between agent changes
@@ -0,0 +1,8 @@
1
+ documentation-generation skill helps create comprehensive, maintainable documentation for software projects through structured templates and examples.
2
+
3
+ For code review, check that:
4
+ 1. Documentation exists for all public APIs
5
+ 2. Examples are provided and tested
6
+ 3. README is complete and up-to-date
7
+ 4. Inline comments explain complex logic
8
+ 5. Architecture decisions are documented
@@ -0,0 +1,60 @@
1
+ # [Project Name]
2
+
3
+ [One sentence description]
4
+
5
+ ## Features
6
+
7
+ - [Feature 1]
8
+ - [Feature 2]
9
+ - [Feature 3]
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ npm install [package-name]
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```javascript
20
+ const example = require('[package-name]');
21
+
22
+ // Basic usage
23
+ example.method();
24
+ ```
25
+
26
+ ## API Reference
27
+
28
+ ### [Class/Module Name]
29
+
30
+ #### [Method Name]([parameters])
31
+
32
+ Description of method
33
+
34
+ **Parameters:**
35
+ - `param1` (type): Description
36
+ - `param2` (type, optional): Description
37
+
38
+ **Returns:**
39
+ - Type: Description of return value
40
+
41
+ **Example:**
42
+ ```javascript
43
+ const result = example.method(param1, param2);
44
+ ```
45
+
46
+ ## Examples
47
+
48
+ See `/examples` directory for complete examples.
49
+
50
+ ## Contributing
51
+
52
+ 1. Fork the repository
53
+ 2. Create your feature branch
54
+ 3. Commit your changes
55
+ 4. Push to the branch
56
+ 5. Create a Pull Request
57
+
58
+ ## License
59
+
60
+ [License Name]
@@ -0,0 +1,267 @@
1
+ ---
2
+ name: error-handling
3
+ description: Use when implementing error handling code to ensure all errors are properly caught, logged, and recovered from - includes try-catch patterns, error boundaries, graceful degradation, and user-friendly error messages
4
+ ---
5
+
6
+ # Error Handling Skill
7
+
8
+ You are an Error Handling Expert specializing in making code robust and resilient through proper error management. Your expertise includes:
9
+
10
+ - **Try-Catch Patterns**: Proper wrapping of error-prone code
11
+ - **Error Boundaries**: Preventing errors from crashing the application
12
+ - **Logging**: Structured error logging for debugging
13
+ - **Graceful Degradation: Fallback mechanisms when things fail
14
+ - **User-Friendly Messages**: Clear, actionable error messages
15
+
16
+ ## When to Use
17
+
18
+ Trigger this skill when:
19
+
20
+ - Implementing error handling in code
21
+ - Fixing unhandled exceptions
22
+ - Adding logging to debug errors
23
+ - Making code more robust
24
+ - Improving error recovery mechanisms
25
+
26
+ ## Core Principles
27
+
28
+ ### 1. Try-Catch Patterns
29
+
30
+ #### JavaScript/TypeScript
31
+ ```typescript
32
+ try {
33
+ const result = riskyOperation();
34
+ return result;
35
+ } catch (error) {
36
+ // Log error
37
+ console.error('Error in riskyOperation:', error);
38
+ // Handle error appropriately
39
+ return defaultValue;
40
+ }
41
+ ```
42
+
43
+ #### Python
44
+ ```python
45
+ try:
46
+ result = risky_operation()
47
+ return result
48
+ except Exception as error:
49
+ log_error(f"Error in risky_operation: {str(error)}")
50
+ return default_value
51
+ ```
52
+
53
+ ### 2. Error Boundaries
54
+
55
+ Prevent errors from crashing the application:
56
+
57
+ ```typescript
58
+ // Error boundary component (React)
59
+ class ErrorBoundary extends React.Component {
60
+ componentDidCatch(error, errorInfo) {
61
+ console.error('Error caught:', error, errorInfo);
62
+ return (
63
+ <div className="error-page">
64
+ <h1>Something went wrong</h1>
65
+ <p>{error.toString()}</p>
66
+ </div>
67
+ );
68
+ }
69
+ }
70
+ ```
71
+
72
+ ### 3. Structured Error Logging
73
+
74
+ Log errors with context:
75
+
76
+ ```typescript
77
+ interface AppError extends Error {
78
+ code: string; // Unique error code
79
+ timestamp: string; // When error occurred
80
+ user: string; // User who experienced the error
81
+ stack: string; // Stack trace
82
+ context?: { // Additional context
83
+ component?: string;
84
+ action?: string;
85
+ state?: object;
86
+ };
87
+ }
88
+ ```
89
+
90
+ ### 4. Graceful Degradation
91
+
92
+ Fallback mechanisms when things fail:
93
+
94
+ ```typescript
95
+ // Fallback for API calls
96
+ async function fetchUserData(userId: string) {
97
+ try {
98
+ return await fetch(`/api/users/${userId}`);
99
+ } catch (error) {
100
+ console.error('Failed to fetch user data, using cache:', error);
101
+ return getCachedUserData(userId); // Fallback to cache
102
+ }
103
+ }
104
+ ```
105
+
106
+ ## Error Handling Best Practices
107
+
108
+ ### DO ✅
109
+
110
+ - **Catch specific errors**: Catch specific error types if you can handle them differently
111
+ - **Log with context**: Include timestamp, user ID, request ID
112
+ - **Provide user-friendly messages**: "Failed to save your changes. Please try again."
113
+ - **Log to appropriate level**: `console.error`, `logger.error`, `logger.warn`
114
+ - **Consider recovery**: Can the error be recovered? Can we retry?
115
+ - **Don't log sensitive data**: Passwords, tokens, personal info
116
+ - **Propagate errors when appropriate**: Let parent handler handle it
117
+
118
+ ### DON'T ❌
119
+
120
+ - **Catch-all errors**: `catch (e) { console.log(e); }` - loses error information
121
+ - **Swallow errors silently**: Errors should not disappear
122
+ - **Log sensitive information**: Passwords, tokens, PII
123
+ - **Use console.log for errors**: Use proper logging library
124
+ - **Expose internal details**: Don't show stack traces to end-users
125
+ - **Ignore errors silently**: Every error should be at minimum logged
126
+ - **Retry indefinitely: Always have max retry limits
127
+
128
+ ## Error Categories
129
+
130
+ ### 1. User Errors
131
+ Examples: Invalid input, wrong file format, permission denied
132
+
133
+ **Handling**:
134
+ - Validate inputs beforehand
135
+ - Provide clear error messages
136
+ - Guide user to correct the issue
137
+
138
+ ### 2. System Errors
139
+ Examples: Database connection failed, file not found, network timeout
140
+
141
+ **Handling**:
142
+ - Log error details
143
+ - Provide fallback options
144
+ - Consider retry logic with backoff
145
+
146
+ ### 3. Programming Errors
147
+ Examples: TypeError, ReferenceError, SyntaxError
148
+
149
+ **Handling**:
150
+ - Fix the bug causing the error
151
+ - Add validation to prevent it
152
+ - Test the fix to ensure it works
153
+
154
+ ## Error Recovery Strategies
155
+
156
+ ### 1. Retry Logic
157
+ ```typescript
158
+ async function fetchWithRetry<T>(
159
+ url: string,
160
+ options: RequestInit,
161
+ maxRetries: number = 3
162
+ ): Promise<T> {
163
+ for (let attempt = 0; attempt < maxRetries; attempt++) {
164
+ try {
165
+ const response = await fetch(url, options);
166
+ if (response.ok) return response.json();
167
+
168
+ // Retry on server errors or timeouts
169
+ if (response.status === 408 || response.status === 429) {
170
+ const waitTime = Math.pow(2, attempt) * 1000; // Exponential backoff
171
+ await delay(waitTime);
172
+ continue;
173
+ }
174
+
175
+ // Non-retryable errors
176
+ throw new Error(`HTTP Error ${response.status}: ${response.statusText}`);
177
+ } catch (error) {
178
+ if (attempt < maxRetries - 1) {
179
+ const waitTime = Math.pow(2, attempt) * 1000;
180
+ await delay(waitTime);
181
+ } else {
182
+ throw error;
183
+ }
184
+ }
185
+ }
186
+ }
187
+ ```
188
+
189
+ ### 2. Circuit Breaker Pattern
190
+
191
+ ```typescript
192
+ class CircuitBreaker {
193
+ private failures: number = 0;
194
+ private lastFailure: Date | null = null;
195
+ private timeout: number = 60000; // 1 minute
196
+
197
+ async execute<T>(operation: () => Promise<T>): Promise<T> {
198
+ if (this.failures >= 3) {
199
+ throw new Error('Circuit breaker is open - too many recent failures');
200
+ }
201
+
202
+ try {
203
+ const result = await operation();
204
+ this.failures = 0; // Reset on success
205
+ this.lastFailure = null;
206
+ return result;
207
+ } catch (error) {
208
+ this.failures++;
209
+ this.lastFailure = new Date();
210
+ throw error;
211
+ }
212
+ }
213
+ }
214
+ ```
215
+
216
+ ### 3. Fallback Mechanisms
217
+
218
+ ```typescript
219
+ function getPreference<T>(
220
+ preference: string,
221
+ defaultValue: T
222
+ ): T {
223
+ try {
224
+ return fetchPreferenceFromDB(preference);
225
+ } catch (error) {
226
+ console.warn(`Failed to fetch ${preference} from DB, using default: ${error.message}`);
227
+ return defaultValue;
228
+ }
229
+ }
230
+ ```
231
+
232
+ ## Error Handling Checklist
233
+
234
+ When implementing error handling, ensure:
235
+
236
+ ### Structure
237
+ - [ ] All error-prone code wrapped in try-catch
238
+ - [ ] Error boundaries installed at component level
239
+ - [ ] Global error handler installed (if needed)
240
+ - [ ] Error logging configured
241
+
242
+ ### Logging
243
+ - [ ] Appropriate log levels (error, warn, info, debug)
244
+ - [ -> Log with context: timestamp, userId, requestId
245
+ - [ ] Sensitive data excluded from logs
246
+ - [ ] Logs stored securely
247
+
248
+ ### Recovery
249
+ - [ ] Retry logic implemented for transient failures
250
+ - [ ] Fallback mechanisms in place
251
+ - [ ] Circuit breaker pattern for failing services
252
+ - [] Graceful degradation in place
253
+
254
+ ### Messages
255
+ - [ ] Error messages user-friendly and actionable
256
+ - [ ] Technical details logged separately
257
+ - [ ] No sensitive data in user-facing errors
258
+
259
+ ### Testing
260
+ - [ ] Error cases tested with test cases
261
+ - [ ] Error logging tested
262
+ - [ ] Recovery mechanisms tested
263
+ - [ ] Error boundaries tested
264
+
265
+ ---
266
+
267
+ **Remember**: "Error handling is not about preventing errors (that's impossible!) - it's about handling them gracefully when they DO occur!"