getError_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package gatecode
  2. import (
  3. "errors"
  4. "fmt"
  5. "github.com/gogf/gf/v2/errors/gcode"
  6. "github.com/gogf/gf/v2/errors/gerror"
  7. "runtime"
  8. "testing"
  9. )
  10. func TestGError(t *testing.T) {
  11. err := errors.New("1")
  12. err = gerror.Wrap(err, "2")
  13. err = gerror.Wrap(err, "3")
  14. t.Log(err, nil)
  15. t.Log(fmt.Sprintf("%s", err), "3: 2: 1")
  16. t.Log(fmt.Sprintf("%v", err), "3: 2: 1")
  17. }
  18. func TestGCode(t *testing.T) {
  19. err1 := errors.New("permission denied")
  20. err2 := gerror.WrapCode(gcode.New(10000, "aaaa", nil), err1, "Custom Error")
  21. fmt.Println(err2.Error())
  22. fmt.Println(gerror.Code(err2))
  23. err3 := gerror.Wrap(err2, "sss")
  24. fmt.Println(err3)
  25. }
  26. func TestGErr(t *testing.T) {
  27. err := errors.New("permission denied")
  28. c := gerror.Code(err)
  29. t.Log(c == gcode.CodeNil)
  30. t.Log("www", c.Detail())
  31. cc := gerror.Stack(err)
  32. t.Log(cc)
  33. ccc := gerror.Code(nil)
  34. t.Log(ccc.Detail())
  35. }
  36. func TestErrorCodeIncrease(t *testing.T) {
  37. c1 := getErrCode(1000)
  38. c2 := getErrCode(2000)
  39. for i := 0; i < 10; i++ {
  40. fmt.Println(c1())
  41. }
  42. for i := 0; i < 10; i++ {
  43. fmt.Println(c2())
  44. }
  45. }
  46. func TestErrCode(t *testing.T) {
  47. fmt.Println(runtime.Version())
  48. fmt.Println("GLOBAL_ERR_NIL =>", GLOBAL_ERR_NIL, int(GLOBAL_ERR_NIL), GLOBAL_ERR_NIL.String())
  49. }