Files
any-hub/internal/config/errors.go
2025-11-14 12:11:44 +08:00

27 lines
678 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package config
import "fmt"
// FieldError 提供字段路径与错误原因,便于 CLI 向用户反馈。
type FieldError struct {
Field string
Reason string
}
func (e FieldError) Error() string {
return fmt.Sprintf("%s: %s", e.Field, e.Reason)
}
// newFieldError 创建包含字段路径与原因的 error便于 CLI 定位。
func newFieldError(field, reason string) error {
return FieldError{Field: field, Reason: reason}
}
// hubField 用于拼接 Hub 级字段路径,方便输出 Hub[xxx].Field 形式。
func hubField(name, field string) string {
if name == "" {
return fmt.Sprintf("Hub[].%s", field)
}
return fmt.Sprintf("Hub[%s].%s", name, field)
}