Files
yms-daemon/internal/transaction/errors.go
T

33 lines
1.4 KiB
Go
Raw Normal View History

2026-08-15 02:30:36 +08:00
package transaction
import (
"errors"
"fmt"
)
var (
ErrNotFound = errors.New("transaction record not found") // 请求的事务记录不存在。
ErrActiveExists = errors.New("an unfinished transaction already exists") // 已存在一条未结束的事务,阻塞新事务创建。
ErrStepConflict = errors.New("step key already refers to different intent") // 同一 step key 已被不同意图占用。
ErrStepNotPending = errors.New("step is not waiting for an execution result") // 步骤不处于等待执行结果的待定状态。
2026-08-15 02:30:36 +08:00
)
// ActiveTransactionError 告知调用方当前阻塞新请求的事务。
//
// 当尝试创建新事务却发现数据库中仍存在未结束事务时返回,TransactionID 指向
// 那条正在占用单活动事务槽位的已有事务。其 Unwrap 返回 ErrActiveExists
// 因此调用方既可用 errors.Is 判断大类,也可用 errors.As 取出具体事务 ID。
2026-08-15 02:30:36 +08:00
type ActiveTransactionError struct {
TransactionID string // 当前阻塞新请求的未结束事务 ID。
2026-08-15 02:30:36 +08:00
}
// Error 返回带事务 ID 的阻塞错误描述。
2026-08-15 02:30:36 +08:00
func (e *ActiveTransactionError) Error() string {
return fmt.Sprintf("%s: %s", ErrActiveExists, e.TransactionID)
}
// Unwrap 返回底层哨兵错误 ErrActiveExists,支持 errors.Is 判定。
2026-08-15 02:30:36 +08:00
func (e *ActiveTransactionError) Unwrap() error {
return ErrActiveExists
}