1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930
|
package csvutil
import (
"reflect"
"testing"
)
func TestUnmarshal(t *testing.T) {
fixture := []struct {
desc string
src []byte
in interface{}
out interface{}
}{
{
desc: "type with two records",
src: []byte("String,int\nstring1,1\nstring2,2"),
in: new([]TypeI),
out: &[]TypeI{
{"string1", 1},
{"string2", 2},
},
},
{
desc: "pointer types with two records",
src: []byte("String,int\nstring1,1\nstring2,2"),
in: &[]*TypeI{},
out: &[]*TypeI{
{"string1", 1},
{"string2", 2},
},
},
{
desc: "array - two records",
src: []byte("String,int\nstring1,1\nstring2,2"),
in: new([2]TypeI),
out: &[2]TypeI{
{"string1", 1},
{"string2", 2},
},
},
{
desc: "array - pointer type with two records",
src: []byte("String,int\nstring1,1\nstring2,2"),
in: &[2]*TypeI{},
out: &[2]*TypeI{
{"string1", 1},
{"string2", 2},
},
},
{
desc: "array - pointer type with two records size three",
src: []byte("String,int\nstring1,1\nstring2,2"),
in: &[3]*TypeI{},
out: &[3]*TypeI{
{"string1", 1},
{"string2", 2},
nil,
},
},
{
desc: "array - pointer type with two records size three - initialized",
src: []byte("String,int\nstring1,1\nstring2,2"),
in: &[3]*TypeI{{}, {}, {}},
out: &[3]*TypeI{
{"string1", 1},
{"string2", 2},
nil,
},
},
{
desc: "array - two records size three",
src: []byte("String,int\nstring1,1\nstring2,2"),
in: new([3]TypeI),
out: &[3]TypeI{
{"string1", 1},
{"string2", 2},
{},
},
},
{
desc: "array - two records size one",
src: []byte("String,int\nstring1,1\nstring2,2"),
in: new([1]TypeI),
out: &[1]TypeI{
{"string1", 1},
},
},
{
desc: "array - two records size zero",
src: []byte("String,int\nstring1,1\nstring2,2"),
in: new([0]TypeI),
out: &[0]TypeI{},
},
{
desc: "quoted input",
src: []byte("\n\n\n\"String\",\"int\"\n\"string1,\n\",\"1\"\n\n\n\n\"string2\",\"2\""),
in: &[]TypeI{},
out: &[]TypeI{
{"string1,\n", 1},
{"string2", 2},
},
},
{
desc: "quoted input - with endline",
src: []byte("\n\n\n\"String\",\"int\"\n\"string1,\n\",\"1\"\n\"string2\",\"2\"\n\n\n"),
in: &[]TypeI{},
out: &[]TypeI{
{"string1,\n", 1},
{"string2", 2},
},
},
{
desc: "header only",
src: []byte("String,int\n"),
in: &[]TypeI{},
out: &[]TypeI{},
},
{
desc: "no data",
src: []byte(""),
in: &[]TypeI{},
out: &[]TypeI{},
},
}
for _, f := range fixture {
t.Run(f.desc, func(t *testing.T) {
if err := Unmarshal(f.src, f.in); err != nil {
t.Fatalf("want err=nil; got %v", err)
}
if !reflect.DeepEqual(f.in, f.out) {
t.Errorf("want out=%v; got %v", f.out, f.in)
}
out := reflect.ValueOf(f.out).Elem()
in := reflect.ValueOf(f.in).Elem()
if cout, cin := out.Cap(), in.Cap(); cout != cin {
t.Errorf("want cap=%d; got %d", cout, cin)
}
})
}
t.Run("invalid data", func(t *testing.T) {
type A struct{}
fixtures := []struct {
desc string
data []byte
err error
}{
{
desc: "invalid first line",
data: []byte(`"`),
err: testUnmarshalInvalidFirstLineErr,
},
{
desc: "invalid second line",
data: []byte("line\n\""),
err: testUnmarshalInvalidSecondLineErr,
},
}
for _, f := range fixtures {
t.Run(f.desc, func(t *testing.T) {
var a []A
if err := Unmarshal(f.data, &a); !checkErr(f.err, err) {
t.Errorf("want err=%v; got %v", f.err, err)
}
})
}
})
t.Run("test invalid arguments", func(t *testing.T) {
n := 1
var fixtures = []struct {
desc string
v interface{}
expected string
}{
{"nil interface", interface{}(nil), "csvutil: Unmarshal(nil)"},
{"nil", nil, "csvutil: Unmarshal(nil)"},
{"non pointer struct", struct{}{}, "csvutil: Unmarshal(non-pointer struct {})"},
{"invalid type double pointer int", (**int)(nil), "csvutil: Unmarshal(invalid type **int)"},
{"invalid type int", (*int)(nil), "csvutil: Unmarshal(invalid type *int)"},
{"invalid initialized type int", &n, "csvutil: Unmarshal(invalid type *int)"},
{"invalid type array of slice", (*[2][]TypeI)(nil), "csvutil: Unmarshal(invalid type *[2][]csvutil.TypeI)"},
{"double array", &[2][1]TypeI{}, "csvutil: Unmarshal(invalid type *[2][1]csvutil.TypeI)"},
{"double slice", &[][]TypeI{}, "csvutil: Unmarshal(invalid type *[][]csvutil.TypeI)"},
{"triple slice", &[][][]TypeI{}, "csvutil: Unmarshal(invalid type *[][][]csvutil.TypeI)"},
{"double ptr slice", &[]*[]TypeI{}, "csvutil: Unmarshal(invalid type *[]*[]csvutil.TypeI)"},
{"int slice", &[]int{}, "csvutil: Unmarshal(invalid type *[]int)"},
}
for _, f := range fixtures {
t.Run(f.desc, func(t *testing.T) {
err := Unmarshal([]byte(""), f.v)
if err == nil {
t.Fatalf("want err != nil")
}
if got := err.Error(); got != f.expected {
t.Errorf("want err=%s; got %s", f.expected, got)
}
})
}
})
}
func TestCountLines(t *testing.T) {
fixtures := []struct {
desc string
data []byte
out int
}{
{
desc: "three lines no endline",
data: []byte(`line1,line1
line2,line2,
line3,line3`),
out: 3,
},
{
desc: "three lines",
data: []byte(`line1,line1
line2,line2
line3,line3
`),
out: 3,
},
{
desc: "no data",
data: []byte(``),
out: 0,
},
{
desc: "endline in a quoted string",
data: []byte(`"line
""1""",line1
line2,"line
2"""
`),
out: 2,
},
{
desc: "empty lines",
data: []byte("\n\nline1,line1\n\n\n\nline2,line2\n\n"),
out: 2,
},
{
desc: "1 line ending with quote",
data: []byte(`"line1","line2"`),
out: 1,
},
{
desc: "1 line ending with quote - with endline",
data: []byte(`"line1","line2"
`),
out: 1,
},
{
desc: "2 lines ending with quote",
data: []byte(`"line1","line2"
line2,"line2"`),
out: 2,
},
}
for _, f := range fixtures {
t.Run(f.desc, func(t *testing.T) {
if out := countRecords(f.data); out != f.out {
t.Errorf("want=%d; got %d", f.out, out)
}
})
}
}
func TestMarshal(t *testing.T) {
fixtures := []struct {
desc string
v interface{}
out [][]string
err error
}{
{
desc: "slice with basic type",
v: []TypeI{
{String: "string", Int: 10},
{String: "", Int: 0},
},
out: [][]string{
{"String", "int"},
{"string", "10"},
{"", ""},
},
},
{
desc: "array with basic type",
v: [2]TypeI{
{String: "string", Int: 10},
{String: "", Int: 0},
},
out: [][]string{
{"String", "int"},
{"string", "10"},
{"", ""},
},
},
{
desc: "slice with pointer type",
v: []*TypeI{
{String: "string", Int: 10},
{String: "", Int: 0},
},
out: [][]string{
{"String", "int"},
{"string", "10"},
{"", ""},
},
},
{
desc: "array with pointer type",
v: [2]*TypeI{
{String: "string", Int: 10},
{String: "", Int: 0},
},
out: [][]string{
{"String", "int"},
{"string", "10"},
{"", ""},
},
},
{
desc: "slice pointer",
v: &[]*TypeI{
{String: "string", Int: 10},
},
out: [][]string{
{"String", "int"},
{"string", "10"},
},
},
{
desc: "array pointer",
v: &[1]*TypeI{
{String: "string", Int: 10},
},
out: [][]string{
{"String", "int"},
{"string", "10"},
},
},
{
desc: "slice pointer wrapped in interface",
v: func() (v interface{}) {
v = &[]*TypeI{
{String: "string", Int: 10},
}
return v
}(),
out: [][]string{
{"String", "int"},
{"string", "10"},
},
},
{
desc: "array pointer wrapped in interface",
v: func() (v interface{}) {
v = &[1]*TypeI{
{String: "string", Int: 10},
}
return v
}(),
out: [][]string{
{"String", "int"},
{"string", "10"},
},
},
{
desc: "not a slice or array",
v: int64(1),
err: &InvalidMarshalError{Type: reflect.TypeOf(int64(1))},
},
{
desc: "slice of non structs",
v: []int64{1},
err: &InvalidMarshalError{Type: reflect.TypeOf([]int64{})},
},
{
desc: "array of non pointers",
v: [1]int64{1},
err: &InvalidMarshalError{Type: reflect.TypeOf([1]int64{})},
},
{
desc: "nil value",
v: nilIface,
err: &InvalidMarshalError{Type: reflect.TypeOf(nilIface)},
},
{
desc: "nil ptr value",
v: nilPtr,
err: &InvalidMarshalError{},
},
{
desc: "nil interface ptr value",
v: nilIfacePtr,
err: &InvalidMarshalError{},
},
{
desc: "marshal empty slice",
v: []TypeI{},
out: [][]string{
{"String", "int"},
},
},
{
desc: "marshal nil slice",
v: []TypeI(nil),
out: [][]string{
{"String", "int"},
},
},
{
desc: "marshal invalid struct type",
v: []InvalidType(nil),
err: &UnsupportedTypeError{Type: reflect.TypeOf(struct{}{})},
},
}
for _, f := range fixtures {
t.Run(f.desc, func(t *testing.T) {
b, err := Marshal(f.v)
if f.err != nil {
if !checkErr(f.err, err) {
t.Errorf("want err=%v; got %v", f.err, err)
}
return
} else if err != nil {
t.Errorf("want err=nil; got %v", err)
}
if expected := encodeCSV(t, f.out); string(b) != expected {
t.Errorf("want %s; got %s", expected, string(b))
}
})
}
t.Run("invalid marshal error message", func(t *testing.T) {
fixtures := []struct {
desc string
expected string
v interface{}
}{
{
desc: "int64",
expected: "csvutil: Marshal(invalid type int64)",
v: int64(1),
},
{
desc: "*int64",
expected: "csvutil: Marshal(invalid type *int64)",
v: pint64(1),
},
{
desc: "[]int64",
expected: "csvutil: Marshal(non struct slice []int64)",
v: []int64{},
},
{
desc: "[]int64",
expected: "csvutil: Marshal(non struct slice *[]int64)",
v: &[]int64{},
},
{
desc: "[2]int64",
expected: "csvutil: Marshal(non struct array *[2]int64)",
v: &[2]int64{},
},
{
desc: "[2]*int64",
expected: "csvutil: Marshal(non struct array *[2]*int64)",
v: &[2]*int64{},
},
{
desc: "*[][]*TypeI",
expected: "csvutil: Marshal(non struct slice *[][]*csvutil.TypeI)",
v: &[][]*TypeI{{}},
},
{
desc: "*[]*[]*TypeI",
expected: "csvutil: Marshal(non struct slice *[]*[]*csvutil.TypeI)",
v: &[]*[]*TypeI{{}},
},
{
desc: "*[1][2]*TypeI",
expected: "csvutil: Marshal(non struct array *[1][2]*csvutil.TypeI)",
v: &[1][2]*TypeI{{}},
},
{
desc: "*[1]*[2]*TypeI",
expected: "csvutil: Marshal(non struct array *[1]*[2]*csvutil.TypeI)",
v: &[1]*[2]*TypeI{{}},
},
{
desc: "[1][2]TypeI",
expected: "csvutil: Marshal(non struct array [1][2]csvutil.TypeI)",
v: [1][2]TypeI{{}},
},
{
desc: "nil interface",
expected: "csvutil: Marshal(nil)",
v: nilIface,
},
{
desc: "nil ptr value",
expected: "csvutil: Marshal(nil)",
v: nilPtr,
},
{
desc: "nil interface ptr value",
expected: "csvutil: Marshal(nil)",
v: nilIfacePtr,
},
}
for _, f := range fixtures {
t.Run(f.desc, func(t *testing.T) {
_, err := Marshal(f.v)
if err == nil {
t.Fatal("want err not to be nil")
}
if err.Error() != f.expected {
t.Errorf("want=%s; got %s", f.expected, err.Error())
}
})
}
})
}
type TypeJ struct {
String string `csv:"STR" json:"string"`
Int string `csv:"int" json:"-"`
Embedded16
Float string `csv:"float"`
}
type Embedded16 struct {
Bool bool `json:"bool"`
Uint uint `csv:"-"`
Uint8 uint8 `json:"-"`
}
func TestHeader(t *testing.T) {
fixture := []struct {
desc string
v interface{}
tag string
header []string
err error
}{
{
desc: "simple type with default tag",
v: TypeG{},
tag: "",
header: []string{"String", "Int"},
},
{
desc: "simple type",
v: TypeG{},
tag: "csv",
header: []string{"String", "Int"},
},
{
desc: "simple type with ptr value",
v: &TypeG{},
tag: "csv",
header: []string{"String", "Int"},
},
{
desc: "embedded types with conflict",
v: &TypeA{},
tag: "csv",
header: []string{"string", "bool", "int"},
},
{
desc: "embedded type with tag",
v: &TypeB{},
tag: "csv",
header: []string{"json", "string"},
},
{
desc: "embedded ptr type with tag",
v: &TypeD{},
tag: "csv",
header: []string{"json", "string"},
},
{
desc: "embedded ptr type no tag",
v: &TypeC{},
tag: "csv",
header: []string{"float", "string"},
},
{
desc: "type with omitempty tags",
v: TypeI{},
tag: "csv",
header: []string{"String", "int"},
},
{
desc: "embedded with different json tag",
v: TypeJ{},
tag: "json",
header: []string{"string", "bool", "Uint", "Float"},
},
{
desc: "embedded with default csv tag",
v: TypeJ{},
tag: "csv",
header: []string{"STR", "int", "Bool", "Uint8", "float"},
},
{
desc: "not a struct",
v: int(10),
tag: "csv",
err: &UnsupportedTypeError{Type: reflect.TypeOf(int(0))},
},
{
desc: "slice",
v: []TypeJ{{}},
tag: "csv",
err: &UnsupportedTypeError{Type: reflect.TypeOf([]TypeJ{})},
},
{
desc: "nil interface",
v: nilIface,
tag: "csv",
err: &UnsupportedTypeError{},
},
{
desc: "circular reference type",
v: &A{},
tag: "csv",
header: []string{"Y", "X"},
},
{
desc: "conflicting fields",
v: &Embedded10{},
tag: "csv",
header: []string{"Y"},
},
{
desc: "inline - simple",
v: &Inline{},
tag: "csv",
header: []string{
"int",
"Bool",
"Uint8",
"float",
"prefix-STR",
"prefix-int",
"prefix-Bool",
"prefix-Uint8",
"prefix-float",
"top-string",
"STR",
},
},
{
desc: "inline - chain",
v: &Inline5{},
tag: "csv",
header: []string{"AS", "AAA", "S", "A"},
},
{
desc: "inline - top level",
v: &Inline8{},
tag: "csv",
header: []string{"AA"},
},
{
desc: "nil ptr of TypeF",
v: nilPtr,
tag: "csv",
header: []string{
"int",
"pint",
"int8",
"pint8",
"int16",
"pint16",
"int32",
"pint32",
"int64",
"pint64",
"uint",
"puint",
"uint8",
"puint8",
"uint16",
"puint16",
"uint32",
"puint32",
"uint64",
"puint64",
"float32",
"pfloat32",
"float64",
"pfloat64",
"string",
"pstring",
"bool",
"pbool",
"interface",
"pinterface",
"binary",
"pbinary",
},
},
{
desc: "ptr to nil interface ptr of TypeF",
v: &nilIfacePtr,
tag: "csv",
header: []string{
"int",
"pint",
"int8",
"pint8",
"int16",
"pint16",
"int32",
"pint32",
"int64",
"pint64",
"uint",
"puint",
"uint8",
"puint8",
"uint16",
"puint16",
"uint32",
"puint32",
"uint64",
"puint64",
"float32",
"pfloat32",
"float64",
"pfloat64",
"string",
"pstring",
"bool",
"pbool",
"interface",
"pinterface",
"binary",
"pbinary",
},
},
{
desc: "nil interface ptr of TypeF",
v: nilIfacePtr,
tag: "csv",
header: []string{
"int",
"pint",
"int8",
"pint8",
"int16",
"pint16",
"int32",
"pint32",
"int64",
"pint64",
"uint",
"puint",
"uint8",
"puint8",
"uint16",
"puint16",
"uint32",
"puint32",
"uint64",
"puint64",
"float32",
"pfloat32",
"float64",
"pfloat64",
"string",
"pstring",
"bool",
"pbool",
"interface",
"pinterface",
"binary",
"pbinary",
},
},
{
desc: "ptr to nil interface",
v: &nilIface,
err: &UnsupportedTypeError{Type: reflect.ValueOf(&nilIface).Type().Elem()},
},
}
for _, f := range fixture {
t.Run(f.desc, func(t *testing.T) {
h, err := Header(f.v, f.tag)
if !checkErr(f.err, err) {
t.Errorf("want err=%v; got %v", f.err, err)
}
if !reflect.DeepEqual(h, f.header) {
t.Errorf("want header=%v; got %v", f.header, h)
}
})
}
t.Run("test nil value error message", func(t *testing.T) {
const expected = "csvutil: unsupported type: nil"
h, err := Header(nilIface, "")
if h != nil {
t.Errorf("want h=nil; got %v", h)
}
if err.Error() != expected {
t.Errorf("want err=%s; got %s", expected, err.Error())
}
})
}
func TestParity(t *testing.T) {
type A struct {
Int int
Pint *int
OmitInt int `csv:",omitempty"`
OmitPint *int `csv:",omitempty"`
}
in := []A{
{
Int: 0,
Pint: pint(0),
OmitInt: 0,
OmitPint: pint(0),
},
{
Int: 1,
Pint: pint(1),
OmitInt: 1,
OmitPint: pint(1),
},
{
Int: 0,
Pint: nil,
OmitInt: 0,
OmitPint: nil,
},
}
b, err := Marshal(in)
if err != nil {
t.Fatalf("want err=nil; got %v", err)
}
var out []A
if err := Unmarshal(b, &out); err != nil {
t.Fatalf("want err=nil; got %v", err)
}
if !reflect.DeepEqual(in, out) {
t.Errorf("want out=%v; got %v", in, out)
}
}
func checkErr(expected, err error) bool {
if expected == err {
return true
}
eVal := reflect.New(reflect.TypeOf(expected))
if !asError(err, eVal.Interface()) {
return false
}
return reflect.DeepEqual(eVal.Elem().Interface(), expected)
}
// asError is a copy of errors.As to support older Go versions.
//
// This copy exists because we want to avoid dependencies like:
// "golang.org/x/xerrors"
func asError(err error, target interface{}) bool {
if target == nil {
panic("errors: target cannot be nil")
}
val := reflect.ValueOf(target)
typ := val.Type()
if typ.Kind() != reflect.Ptr || val.IsNil() {
panic("errors: target must be a non-nil pointer")
}
targetType := typ.Elem()
if targetType.Kind() != reflect.Interface && !targetType.Implements(errorType) {
panic("errors: *target must be interface or implement error")
}
for err != nil {
if reflect.TypeOf(err).AssignableTo(targetType) {
val.Elem().Set(reflect.ValueOf(err))
return true
}
if x, ok := err.(interface{ As(interface{}) bool }); ok && x.As(target) {
return true
}
err = unwrap(err)
}
return false
}
var errorType = reflect.TypeOf((*error)(nil)).Elem()
// unwrap is a copy of errors.Unwrap for older Go versions and to avoid
// dependencies.
func unwrap(err error) error {
u, ok := err.(interface {
Unwrap() error
})
if !ok {
return nil
}
return u.Unwrap()
}
|