|
| 1 | +import { useState } from 'react'; |
1 | 2 | import { HighlightBox } from '../components/HighlightBox'; |
2 | 3 | import { MermaidDiagram } from '../components/MermaidDiagram'; |
3 | 4 | import { CodeBlock } from '../components/CodeBlock'; |
4 | 5 |
|
| 6 | +function Introduction({ |
| 7 | + isExpanded, |
| 8 | + onToggle, |
| 9 | +}: { |
| 10 | + isExpanded: boolean; |
| 11 | + onToggle: () => void; |
| 12 | +}) { |
| 13 | + return ( |
| 14 | + <div className="mb-8 bg-gradient-to-r from-[var(--terminal-green)]/10 to-[var(--cyber-blue)]/10 rounded-xl border border-[var(--border-subtle)] overflow-hidden"> |
| 15 | + <button |
| 16 | + onClick={onToggle} |
| 17 | + className="w-full px-6 py-4 flex items-center justify-between hover:bg-white/5 transition-colors" |
| 18 | + > |
| 19 | + <div className="flex items-center gap-3"> |
| 20 | + <span className="text-2xl">🛡️</span> |
| 21 | + <span className="text-xl font-bold text-[var(--text-primary)]"> |
| 22 | + 错误处理导读 |
| 23 | + </span> |
| 24 | + </div> |
| 25 | + <span |
| 26 | + className={`transform transition-transform text-[var(--text-muted)] ${isExpanded ? 'rotate-180' : ''}`} |
| 27 | + > |
| 28 | + ▼ |
| 29 | + </span> |
| 30 | + </button> |
| 31 | + |
| 32 | + {isExpanded && ( |
| 33 | + <div className="px-6 pb-6 space-y-4"> |
| 34 | + <div className="bg-[var(--bg-terminal)]/50 rounded-lg p-4 border-l-4 border-[var(--terminal-green)]"> |
| 35 | + <h4 className="text-[var(--terminal-green)] font-bold mb-2"> |
| 36 | + 🎯 错误处理目标 |
| 37 | + </h4> |
| 38 | + <p className="text-[var(--text-secondary)] text-sm"> |
| 39 | + CLI 的错误处理系统旨在:<strong>分类错误</strong>(可恢复 vs 不可恢复)、 |
| 40 | + <strong>尝试恢复</strong>(重试、回退)、<strong>优雅降级</strong>(用户通知、日志记录)。 |
| 41 | + </p> |
| 42 | + </div> |
| 43 | + |
| 44 | + <div className="bg-[var(--bg-terminal)]/50 rounded-lg p-4 border-l-4 border-[var(--amber)]"> |
| 45 | + <h4 className="text-[var(--amber)] font-bold mb-2"> |
| 46 | + 🔧 错误类型层次 |
| 47 | + </h4> |
| 48 | + <div className="grid grid-cols-2 md:grid-cols-4 gap-2 mt-2"> |
| 49 | + <div className="bg-[var(--bg-card)] p-2 rounded text-center"> |
| 50 | + <div className="text-xs text-[var(--terminal-green)]">CLIError</div> |
| 51 | + <div className="text-[10px] text-[var(--text-muted)]">基础类</div> |
| 52 | + </div> |
| 53 | + <div className="bg-[var(--bg-card)] p-2 rounded text-center"> |
| 54 | + <div className="text-xs text-[var(--cyber-blue)]">APIError</div> |
| 55 | + <div className="text-[10px] text-[var(--text-muted)]">网络错误</div> |
| 56 | + </div> |
| 57 | + <div className="bg-[var(--bg-card)] p-2 rounded text-center"> |
| 58 | + <div className="text-xs text-[var(--amber)]">ToolError</div> |
| 59 | + <div className="text-[10px] text-[var(--text-muted)]">工具失败</div> |
| 60 | + </div> |
| 61 | + <div className="bg-[var(--bg-card)] p-2 rounded text-center"> |
| 62 | + <div className="text-xs text-[var(--purple)]">AuthError</div> |
| 63 | + <div className="text-[10px] text-[var(--text-muted)]">认证失败</div> |
| 64 | + </div> |
| 65 | + </div> |
| 66 | + </div> |
| 67 | + |
| 68 | + <div className="bg-[var(--bg-terminal)]/50 rounded-lg p-4 border-l-4 border-[var(--cyber-blue)]"> |
| 69 | + <h4 className="text-[var(--cyber-blue)] font-bold mb-2"> |
| 70 | + 🔄 可恢复错误 |
| 71 | + </h4> |
| 72 | + <ul className="text-[var(--text-secondary)] text-sm space-y-1"> |
| 73 | + <li>• <strong>429 Rate Limit</strong> - 等待后重试</li> |
| 74 | + <li>• <strong>500/502/503/504</strong> - 服务端临时错误,可重试</li> |
| 75 | + <li>• <strong>工具执行失败</strong> - 通常可重试或回退</li> |
| 76 | + </ul> |
| 77 | + </div> |
| 78 | + |
| 79 | + <div className="bg-[var(--bg-terminal)]/50 rounded-lg p-4 border-l-4 border-[var(--purple)]"> |
| 80 | + <h4 className="text-[var(--purple)] font-bold mb-2">📊 关键数字</h4> |
| 81 | + <div className="grid grid-cols-2 md:grid-cols-4 gap-3"> |
| 82 | + <div className="text-center"> |
| 83 | + <div className="text-xl font-bold text-[var(--terminal-green)]">6+</div> |
| 84 | + <div className="text-xs text-[var(--text-muted)]">错误类型</div> |
| 85 | + </div> |
| 86 | + <div className="text-center"> |
| 87 | + <div className="text-xl font-bold text-[var(--cyber-blue)]">3</div> |
| 88 | + <div className="text-xs text-[var(--text-muted)]">最大重试</div> |
| 89 | + </div> |
| 90 | + <div className="text-center"> |
| 91 | + <div className="text-xl font-bold text-[var(--amber)]">指数</div> |
| 92 | + <div className="text-xs text-[var(--text-muted)]">退避策略</div> |
| 93 | + </div> |
| 94 | + <div className="text-center"> |
| 95 | + <div className="text-xl font-bold text-[var(--purple)]">✓</div> |
| 96 | + <div className="text-xs text-[var(--text-muted)]">遥测集成</div> |
| 97 | + </div> |
| 98 | + </div> |
| 99 | + </div> |
| 100 | + </div> |
| 101 | + )} |
| 102 | + </div> |
| 103 | + ); |
| 104 | +} |
| 105 | + |
5 | 106 | export function ErrorHandling() { |
| 107 | + const [isIntroExpanded, setIsIntroExpanded] = useState(true); |
6 | 108 | const errorFlowChart = `flowchart TD |
7 | 109 | start["错误发生"] |
8 | 110 | capture["错误捕获<br/>Error Boundary"] |
@@ -554,6 +656,11 @@ function attemptJSONFix( |
554 | 656 |
|
555 | 657 | return ( |
556 | 658 | <div className="space-y-8"> |
| 659 | + <Introduction |
| 660 | + isExpanded={isIntroExpanded} |
| 661 | + onToggle={() => setIsIntroExpanded(!isIntroExpanded)} |
| 662 | + /> |
| 663 | + |
557 | 664 | {/* 概述 */} |
558 | 665 | <section> |
559 | 666 | <h2 className="text-2xl font-bold text-cyan-400 mb-4">错误处理系统</h2> |
|
0 commit comments