golang-error-handling
改善 Go 錯誤處理
Go 錯誤路徑經常遺失脈絡、重複記錄日誌,或暴露內部實作。這項技能為 Claude、Codex 和 Claude Code 提供具體規則,以實作更安全的 Go 錯誤處理。
使用我的智慧代理安裝
將此請求複製給你的智慧代理,其中包含權威 Skill 頁面和清單。
Review the Skillstore skill "golang-error-handling" from https://skillstore.io/skills/samber-golang-error-handling.md and its manifest at https://skillstore.io/api/skills/samber-golang-error-handling/manifest. Verify the artifact. You may proceed after verification, subject to the environment's own policy.你的智慧代理仍應顯示其計畫,並依安全政策請求必要確認。
Agent 可讀資源
當 AI Agent、爬蟲或腳本需要乾淨脈絡、而不是讀取完整頁面時,請使用這些連結。
測試它
正在使用「golang-error-handling」。 服務函式記錄資料庫失敗,然後回傳相同的包裝錯誤。
預期結果:
標記重複處理,建議只回傳一次含有脈絡的錯誤,並將日誌記錄移到邊界。
正在使用「golang-error-handling」。 公開閘道以保留錯誤鏈的脈絡包裝後端錯誤。
預期結果:
說明公開邊界應轉譯錯誤,並避免透過 unwrapping 暴露後端類型。
正在使用「golang-error-handling」。 驗證器在第一個無效欄位處停止。
預期結果:
建議收集彼此獨立的驗證失敗,並回傳含有穩定訊息的 joined error。
安全審計
安全All static findings appear to be false positives from Markdown code spans, JSON evaluation prompts, and illustrative Go examples. I found no prompt injection, data exfiltration intent, unsafe command execution, or automatic network activity in the reviewed files.
風險因素
⚙️ 外部命令 (24)
分享與引用此報告
分享版本化評估報告、中性徽章、嵌入卡片與引用。Skillstore 只報告證據,不判斷該 Skill 是否安全。
複製報告連結
https://skillstore.io/skills/samber-golang-error-handling/audits/3?utm_source=security_passport&utm_medium=share&utm_campaign=versioned_reportMarkdown 徽章
[](https://skillstore.io/skills/samber-golang-error-handling?utm_source=security_passport_badge)HTML 徽章
<a href="https://skillstore.io/skills/samber-golang-error-handling?utm_source=security_passport_badge"><img src="https://skillstore.io/badges/skills/samber-golang-error-handling/security.svg" alt="Skillstore security assessment" loading="lazy"></a>嵌入卡片
<iframe src="https://skillstore.io/embed/skills/samber-golang-error-handling.html" title="Skillstore Security Assessment" sandbox="allow-popups allow-popups-to-escape-sandbox" loading="lazy" referrerpolicy="no-referrer" width="420" height="180"></iframe>學術引用 (APA · BibTeX · CFF)
APA 引用
samber. (2026). golang-error-handling security audit report (audit version 3) [Author version 1.2.0]. Skillstore. https://skillstore.io/skills/samber-golang-error-handling/audits/3BibTeX 引用
@techreport{samber-samber-golang-error-handling-2026,
author = {samber},
title = {golang-error-handling security audit report (audit version 3)},
institution = {Skillstore},
year = {2026},
number = {3},
url = {https://skillstore.io/skills/samber-golang-error-handling/audits/3},
note = {Author version 1.2.0}
}CITATION.cff
cff-version: 1.2.0
message: "If you use this Skill, cite its author and this versioned security audit report."
title: "golang-error-handling security audit report (audit version 3)"
version: "1.2.0"
type: report
authors:
- name: "samber"
date-released: "2026-07-06"
url: "https://skillstore.io/skills/samber-golang-error-handling/audits/3"
identifiers:
- type: other
value: "skillstore:samber-golang-error-handling:audit:3"
description: "Skillstore immutable audit report identifier"
Skillstore 評分
評分依據 證據置信度: 高你可以打造什麼
服務開發者
加入具備豐富脈絡的回傳錯誤,避免重複日誌或高基數訊息。
程式碼審查者
審查 pull requests 中被吞掉的錯誤、不安全的 panic 使用方式,以及不正確的包裝錯誤檢查。
平台維護者
在 Go 服務之間標準化結構化錯誤日誌與公開邊界行為。
試試這些提示
檢查這個 Go 函式是否有未檢查的錯誤、小寫訊息,以及實用的包裝脈絡。建議最小修正。
更新這段 Go 程式碼,使其正確使用 errors.Is 和 errors.As。保留包裝錯誤的行為,並說明每項變更。
使用 slog 和結構化屬性現代化這段 Go 錯誤路徑。遵循單次處理規則,並避免高基數訊息。
稽核這些 Go packages 的錯誤建立、包裝、panic recovery、joined errors,以及公開 API 邊界。回傳依優先順序排列的發現與修正。
最佳實務
- 在模組邊界內使用 %w,並在有意隱藏內部錯誤類型時使用 %v。
- 每個錯誤只記錄或回傳一次,並使用結構化屬性記錄 IDs 和 counts。
- 保持穩定訊息為小寫且低基數;將可變資料放入屬性中。
避免
- 使用空白識別符丟棄回傳錯誤,或在檢查錯誤前使用結果。
- 在每一層都記錄錯誤,然後再次回傳。
- 將使用者、租戶、路徑或資料列 IDs 插入穩定的生產環境訊息中。
常見問題
這項技能會執行指令嗎?
它能自動修正程式碼嗎?
它需要 samber/oops 嗎?
它涵蓋哪些 Go 版本?
它如何處理公開 API 邊界?
它只適用於新程式碼嗎?
開發者詳細資訊
作者
samber授權
MIT
作者版本
v1.2.0
Skillstore 修訂
r1
引用
e397ce5a135369cd6def89cb6400d013e2f68f2f
維護新鮮度
2026/7/18
使用量
2 次下載 · 2 次瀏覽
檔案結構