Files
2026-08-17 10:10:14 +08:00

33 lines
1.4 KiB
Go
Raw Permalink 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 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") // 步骤不处于等待执行结果的待定状态。
)
// ActiveTransactionError 告知调用方当前阻塞新请求的事务。
//
// 当尝试创建新事务却发现数据库中仍存在未结束事务时返回,TransactionID 指向
// 那条正在占用单活动事务槽位的已有事务。其 Unwrap 返回 ErrActiveExists
// 因此调用方既可用 errors.Is 判断大类,也可用 errors.As 取出具体事务 ID。
type ActiveTransactionError struct {
TransactionID string // 当前阻塞新请求的未结束事务 ID。
}
// Error 返回带事务 ID 的阻塞错误描述。
func (e *ActiveTransactionError) Error() string {
return fmt.Sprintf("%s: %s", ErrActiveExists, e.TransactionID)
}
// Unwrap 返回底层哨兵错误 ErrActiveExists,支持 errors.Is 判定。
func (e *ActiveTransactionError) Unwrap() error {
return ErrActiveExists
}