fix(query): 保留业务异常并消除选项复用状态
Verify / verify (push) Canceled after 0s

This commit is contained in:
zhangdeman committed 2026-11-28 03:15:47 -08:00
1 parent d2a9033695
commit 734d389a7c
5 files changed
+91 -13

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
package failure
import (
"errors"
"fmt"
"testing"
"git.zhangdeman.cn/zhangdeman/ginframework/fault"
)
type numericBusinessError struct{}
func (*numericBusinessError) Error() string { return "private business message" }
func (*numericBusinessError) Code() int { return 1001 }
type flexibleBusinessError struct{ code any }
func (*flexibleBusinessError) Error() string { return "private business message" }
func (e *flexibleBusinessError) Code() any { return e.code }
func TestClassifiedExtensionErrorsPreserveIdentity(t *testing.T) {
for _, cause := range []error{&numericBusinessError{}, &flexibleBusinessError{code: 1002}, fmt.Errorf("callback: %w", &numericBusinessError{}), fmt.Errorf("callback: %w", &flexibleBusinessError{code: 1003})} {
if got := Wrap(901106, "read database record failed", cause); got != cause {
t.Fatal("classified application error was wrapped")
}
}
for _, cause := range []error{&flexibleBusinessError{code: "1002"}, &flexibleBusinessError{}, errors.New("raw driver failure")} {
got := Wrap(901106, "read database record failed", cause)
if !fault.Internal(got) || !errors.Is(got, cause) {
t.Fatal("unclassified cause lost source classification")
}
}
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.