npx skills add https://github.com/cristiano-pacheco/ai-rules --skill go-error为模块级 errs 包生成类型化的自定义错误。
将错误放置在:
internal/modules/<module>/errs/errs.go
每个模块的错误文件遵循以下结构:
package errsnet/httpbrickserrs "github.com/cristiano-pacheco/bricks/pkg/errs"var (...) 代码块brickserrs.New("<MODULE>_<NN>", "<message>", http.<Status>, nil)Generate typed custom errors for module-level errs packages.
Place errors in:
internal/modules/<module>/errs/errs.go
Each module error file follows:
package errsnet/httpbrickserrs "github.com/cristiano-pacheco/bricks/pkg/errs"var (...) block with exported error variables广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
package errs
import (
"net/http"
brickserrs "github.com/cristiano-pacheco/bricks/pkg/errs"
)
var (
// ErrProfileValidationFailed 在个人资料验证失败时返回。
ErrProfileValidationFailed = brickserrs.New(
"PROFILE_01",
"profile validation failed",
http.StatusBadRequest,
nil,
)
// ErrProfileNotFound 在未找到个人资料时返回。
ErrProfileNotFound = brickserrs.New("PROFILE_02", "profile not found", http.StatusNotFound, nil)
)
// NewProfileValidationError 返回一个包含字段级详细信息的结构化验证错误。
func NewProfileValidationError(details []brickserrs.Detail) *brickserrs.Error {
return brickserrs.New(
ErrProfileValidationFailed.Code,
ErrProfileValidationFailed.Message,
ErrProfileValidationFailed.Status,
details,
)
}
catalog、profile、ai、export)ErrProfileNotFound)"profile not found")http.StatusNotFound)internal/modules/<module>/errs/errs.goCATALOG_01、CATALOG_02、...、CATALOG_09CATALOG_10、CATALOG_11、...var (...) 代码块中NewXxxValidationError(details []brickserrs.Detail) *brickserrs.Error 函数.Code、.Message 和 .Status 字段errors.New(...)locales/en.json 的 "errors" 键下添加一个翻译条目"PROFILE_02": "Profile not found"locales/pt_BR.json),也在其中添加相同的键Err + 清晰的领域短语(PascalCase)
ErrProfileNotFound、ErrAIGenerationFailed<MODULE>_<NN>
CATALOG_09、EXPORT_15、AI_07brickserrs.New() 中全部小写——区域设置文件(locales/en.json)提供面向用户的大写形式"profile not found"、"invalid prompt type"、"ai provider unavailable"http.StatusBadRequesthttp.StatusUnauthorized / http.StatusForbiddenhttp.StatusNotFoundhttp.StatusConflicthttp.StatusTooManyRequestshttp.StatusBadGatewayhttp.StatusServiceUnavailablehttp.StatusInternalServerErrorinternal/modules/<module>/errs/errs.gobrickserrs.New(...) 添加导出的 Err... 变量NewXxxValidationError(details []brickserrs.Detail) 辅助函数error 返回替换为类型化的 errs.Err...(如果适用)locales/en.json 的 "errors" 下为新错误添加翻译,使用正确的句子大小写值locales/pt_BR.json)中添加相同的翻译键make lint 以捕获样式和静态分析问题make nilaway 以确保没有引入空指针解引用if input.Phone == "" {
return errs.ErrPhoneNumberRequired
}
if profile == nil {
return errs.ErrProfileNotFound
}
internal/modules/<module>/errslocales/en.json 和所有其他现有区域设置文件中添加区域设置条目brickserrs.New() 中的消息始终为小写;面向用户的大写形式存在于区域设置文件中每周安装数
1
仓库
首次出现
今天
安全审计
安装于
zencoder1
amp1
cline1
openclaw1
opencode1
cursor1
brickserrs.New("<MODULE>_<NN>", "<message>", http.<Status>, nil)package errs
import (
"net/http"
brickserrs "github.com/cristiano-pacheco/bricks/pkg/errs"
)
var (
// ErrProfileValidationFailed is returned when profile validation fails.
ErrProfileValidationFailed = brickserrs.New(
"PROFILE_01",
"profile validation failed",
http.StatusBadRequest,
nil,
)
// ErrProfileNotFound is returned when the profile is not found.
ErrProfileNotFound = brickserrs.New("PROFILE_02", "profile not found", http.StatusNotFound, nil)
)
// NewProfileValidationError returns a structured validation error with field-level details.
func NewProfileValidationError(details []brickserrs.Detail) *brickserrs.Error {
return brickserrs.New(
ErrProfileValidationFailed.Code,
ErrProfileValidationFailed.Message,
ErrProfileValidationFailed.Status,
details,
)
}
Identify error details :
catalog, profile, ai, export)ErrProfileNotFound)"profile not found")http.StatusNotFound)Find the next code :
internal/modules/<module>/errs/errs.goCATALOG_01, CATALOG_02, ..., CATALOG_09CATALOG_10, CATALOG_11, ...Add the new error :
var (...) blockAdd a helper constructor if needed :
NewXxxValidationError(details []brickserrs.Detail) *brickserrs.Error function.Code, .Message, and .Status fieldsValidate usage path :
errors.New(...) from business flows when a typed module error existsUpdate translations (mandatory) :
locales/en.json under the "errors" key"PROFILE_02": "Profile not found"locales/pt_BR.json), add the same key there tooErr + clear domain phrase in PascalCase
ErrProfileNotFound, ErrAIGenerationFailed<MODULE>_<NN>
CATALOG_09, EXPORT_15, AI_07brickserrs.New() — the locale file (locales/en.json) provides the user-facing capitalized form"profile not found", "invalid prompt type", "ai provider unavailable"http.StatusBadRequesthttp.StatusUnauthorized / http.StatusForbiddenhttp.StatusNotFoundhttp.StatusConflicthttp.StatusTooManyRequestshttp.StatusBadGatewayhttp.StatusServiceUnavailablehttp.StatusInternalServerErrorinternal/modules/<module>/errs/errs.goErr... variable with brickserrs.New(...)NewXxxValidationError(details []brickserrs.Detail) helper if it is a validation errorerrs.Err... where applicablelocales/en.json under "errors" with proper sentence-case valuelocales/pt_BR.json)make lint to catch style and static analysis issuesmake nilaway to ensure no nil pointer dereferences are introducedif input.Phone == "" {
return errs.ErrPhoneNumberRequired
}
if profile == nil {
return errs.ErrProfileNotFound
}
internal/modules/<module>/errslocales/en.json and all other existing locale filesbrickserrs.New() are always lowercase; user-facing capitalization lives in the locale fileWeekly Installs
1
Repository
First Seen
Today
Security Audits
Installed on
zencoder1
amp1
cline1
openclaw1
opencode1
cursor1
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
109,600 周安装
邮件网关集成指南:Resend、SendGrid、Mailgun、SMTP2Go 多提供商API代码示例
342 周安装
react-grab:AI 开发助手,一键复制 React 组件上下文到剪贴板
343 周安装
Go语言最佳实践指南:Google/Uber生产级代码规范与Go 1.25新特性
347 周安装
Solana 命令行工具:支付、钱包与交易一站式管理 | Solana CLI 指南
347 周安装
系统设计框架:大规模分布式系统设计原则、四步流程与构建模块详解
360 周安装
OpenAI Responses API 指南:有状态对话、内置工具与 Chat Completions 对比
346 周安装