← Back to list

go-error-wrapping
by JamesPrial
WIP - collection of various Claude stuff i make/use/have_Claude_hallucinate
⭐ 2🍴 0📅 Jan 23, 2026
SKILL.md
name: go-error-wrapping description: Wrap errors with context using fmt.Errorf %w pattern
Error Wrapping with %w
Pattern
Use fmt.Errorf with %w to add context while preserving the error chain.
CORRECT
func ReadConfig(path string) (*Config, error) {
data, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("read config %s: %w", path, err)
}
var cfg Config
if err := json.Unmarshal(data, &cfg); err != nil {
return nil, fmt.Errorf("parse config %s: %w", path, err)
}
return &cfg, nil
}
WRONG
// Bad: Loses error chain
return nil, fmt.Errorf("read config failed: %v", err)
// Bad: No context
return nil, err
// Bad: String concatenation
return nil, errors.New("read config: " + err.Error())
Key Rules
- Use
%wto wrap, not%vor%s - Add meaningful context (file names, IDs, operations)
- Keep messages lowercase, no punctuation
- Preserve original error for type checking
Example Chain
// Error flows up with context at each layer:
// "process user 123: read config /etc/app.conf: open /etc/app.conf: no such file or directory"
func ProcessUser(id int) error {
cfg, err := ReadConfig("/etc/app.conf")
if err != nil {
return fmt.Errorf("process user %d: %w", id, err)
}
// use cfg...
return nil
}
Score
Total Score
65/100
Based on repository quality metrics
✓SKILL.md
SKILL.mdファイルが含まれている
+20
✓LICENSE
ライセンスが設定されている
+10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
✓最近の活動
1ヶ月以内に更新
+10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
✓タグ
1つ以上のタグが設定されている
+5
Reviews
💬
Reviews coming soon
